make datePatterns hide
Showing
1 changed file
with
3 additions
and
3 deletions
| ... | @@ -61,7 +61,7 @@ func DateFormat(t time.Time, layout string) (datestring string) { | ... | @@ -61,7 +61,7 @@ func DateFormat(t time.Time, layout string) (datestring string) { |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | // DateFormat pattern rules. | 63 | // DateFormat pattern rules. |
| 64 | var DatePatterns = []string{ | 64 | var datePatterns = []string{ |
| 65 | // year | 65 | // year |
| 66 | "Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003 | 66 | "Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003 |
| 67 | "y", "06", //A two digit representation of a year Examples: 99 or 03 | 67 | "y", "06", //A two digit representation of a year Examples: 99 or 03 |
| ... | @@ -103,14 +103,14 @@ var DatePatterns = []string{ | ... | @@ -103,14 +103,14 @@ var DatePatterns = []string{ |
| 103 | 103 | ||
| 104 | // Parse Date use PHP time format. | 104 | // Parse Date use PHP time format. |
| 105 | func DateParse(dateString, format string) (time.Time, error) { | 105 | func DateParse(dateString, format string) (time.Time, error) { |
| 106 | replacer := strings.NewReplacer(DatePatterns...) | 106 | replacer := strings.NewReplacer(datePatterns...) |
| 107 | format = replacer.Replace(format) | 107 | format = replacer.Replace(format) |
| 108 | return time.ParseInLocation(format, dateString, time.Local) | 108 | return time.ParseInLocation(format, dateString, time.Local) |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | // Date takes a PHP like date func to Go's time format. | 111 | // Date takes a PHP like date func to Go's time format. |
| 112 | func Date(t time.Time, format string) string { | 112 | func Date(t time.Time, format string) string { |
| 113 | replacer := strings.NewReplacer(DatePatterns...) | 113 | replacer := strings.NewReplacer(datePatterns...) |
| 114 | format = replacer.Replace(format) | 114 | format = replacer.Replace(format) |
| 115 | return t.Format(format) | 115 | return t.Format(format) |
| 116 | } | 116 | } | ... | ... |
-
Please register or sign in to post a comment