mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 03:01:28 +00:00
make datePatterns hide
This commit is contained in:
parent
8ba6dbb9a0
commit
2c868a9557
@ -61,7 +61,7 @@ func DateFormat(t time.Time, layout string) (datestring string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DateFormat pattern rules.
|
// DateFormat pattern rules.
|
||||||
var DatePatterns = []string{
|
var datePatterns = []string{
|
||||||
// year
|
// year
|
||||||
"Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
|
"Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
|
||||||
"y", "06", //A two digit representation of a year Examples: 99 or 03
|
"y", "06", //A two digit representation of a year Examples: 99 or 03
|
||||||
@ -103,14 +103,14 @@ var DatePatterns = []string{
|
|||||||
|
|
||||||
// Parse Date use PHP time format.
|
// Parse Date use PHP time format.
|
||||||
func DateParse(dateString, format string) (time.Time, error) {
|
func DateParse(dateString, format string) (time.Time, error) {
|
||||||
replacer := strings.NewReplacer(DatePatterns...)
|
replacer := strings.NewReplacer(datePatterns...)
|
||||||
format = replacer.Replace(format)
|
format = replacer.Replace(format)
|
||||||
return time.ParseInLocation(format, dateString, time.Local)
|
return time.ParseInLocation(format, dateString, time.Local)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Date takes a PHP like date func to Go's time format.
|
// Date takes a PHP like date func to Go's time format.
|
||||||
func Date(t time.Time, format string) string {
|
func Date(t time.Time, format string) string {
|
||||||
replacer := strings.NewReplacer(DatePatterns...)
|
replacer := strings.NewReplacer(datePatterns...)
|
||||||
format = replacer.Replace(format)
|
format = replacer.Replace(format)
|
||||||
return t.Format(format)
|
return t.Format(format)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user