Skip to content

Instantly share code, notes, and snippets.

@xuanyu-h
Created September 9, 2019 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuanyu-h/ca8f5fb481d3350375ff7e460c9c3fa9 to your computer and use it in GitHub Desktop.
Save xuanyu-h/ca8f5fb481d3350375ff7e460c9c3fa9 to your computer and use it in GitHub Desktop.
go date/time format
Go layout Java notation C notation Notes
2016-01-02 yyyy-MM-dd %F ISO 8601
20160102 yyyyMMdd %Y%m%d ISO 8601
January 02, 2006 MMMM dd, yyyyare neat %B %d, %Y
02 January 2006 dd MMMM yyyy %d %B %Y
02-Jan-2006 dd-MMM-yyyy %d-%b-%Y
01/02/06 MM/dd/yy %D US
01/02/2006 MM/dd/yyyy %m/%d/%Y US
010206 MMddyy %m%d%y US
Jan-02-06 MMM-dd-yy %b-%d-%y US
Jan-02-2006 MMM-dd-yyyy %b-%d-%Y US
06 yy %y
Mon EEE %a
Monday EEEE %A
Jan-06 MMM-yy %b-%y
15:04 HH:mm %R
15:04:05 HH:mm:ss %T ISO 8601
3:04 PM K:mm a %l:%M %p US
03:04:05 PM KK:mm:ss a %r US
2006-01-02T15:04:05 yyyy-MM-dd'T'HH:mm:ss %FT%T ISO 8601
2006-01-02T15:04:05-0700 yyyy-MM-dd'T'HH:mm:ssZ %FT%T%z ISO 8601
2 Jan 2006 15:04:05 d MMM yyyy HH:mm:ss %e %b %Y %T
2 Jan 2006 15:04 d MMM yyyy HH:mm %e %b %Y %R
Mon, 2 Jan 2006 15:04:05 MST EEE, d MMM yyyy HH:mm:ss z %a, %e %b %Y %T %Z RFC 1123
@xuanyu-h
Copy link
Author

xuanyu-h commented Sep 9, 2019

input := "2017-08-31"
layout := "2006-01-02"
t, _ := time.Parse(layout, input)
fmt.Println(t)                       // 2017-08-31 00:00:00 +0000 UTC
fmt.Println(t.Format("02-Jan-2006")) // 31-Aug-2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment