GithubHelp home page GithubHelp logo

ghosind / go-date Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 109 KB

The extends of the Golang built-in time package.

Home Page: https://pkg.go.dev/github.com/ghosind/go-date

License: MIT License

Go 100.00%
date datetime datetime-format golang golang-package time time-formatting go-library

go-date's Introduction

Date

test Go Report Card codecov Version Badge License Badge Go Reference

The extends of the Golang built-in time package.

Installation

Run the following command to install the library, which requires Go 1.20 and later versions.

go get -u github.com/ghosind/go-date

Getting Started

This library overwrites the built-in format layouts, the following example is a simple implementation of parsing a string:

str := "2024-01-10 23:59:30"
layout := "YYYY-MM-DD HH:mm:ss"
tm, err := date.Parse(layout, str)
if err != nil {
  // handle error
}
fmt.Print(tm) // 2024-01-10 23:59:30 +0000 CST

You can also use the Format method to format the Time to a string:

tm := Date(2024, time.January, 1, 23, 59, 30, 0)
fmt.Print(fm.Format("YYYY-MM-DD HH:mm:ss")) // 2024-01-10 23:59:30

Available Formats

Format Description Example
YYYY 4-digits year 2023
YY 2-digits year 23
MM 2-digits month 01-12
M Month, beginning at 1 1-12
MMMM The month name January-December
MMM The abbreviated month name Jan-Dec
DD The day of month, 2-digits 01-31
D The day of month, beginning at 1 1-31
dddd The day of week Sunday-Friday
ddd The abbreviated name of weekday Sun-Fri
d The day of week, beginning at 0 (Sunday) 0-6
HH The hour of 24-hour clock, 2-digits 00-23
H The hour of 24-hour clock, beginning at 1 0-23
hh The hour of 12-hour clock, 2-digits 01-12
h The hour of 12-hour clock, beginning at 1 1-12
mm The minutes, 2-digits 00-59
m The minutes 0-59
ss The seconds, 2-digits 00-59
s The seconds 0-59
SSS The milliseconds, 3-digits 000-999
SS The tens of milliseconds, 2-digits 00-99
S The hundreds of milliseconds, 1-digit 0-9
A Post or ante meridiem, in upper case AM, PM
a Post or ante meridiem, in lower case am, pm
Z Timezone offset from UTC, separate by colon -08:00
ZZ Timezone offset from UTC -0800

go-date's People

Contributors

ghosind avatar mend-bolt-for-github[bot] avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.