You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
593 B
28 lines
593 B
package tool
|
|
|
|
import "time"
|
|
|
|
const (
|
|
TimeLayout = "2006-01-02 15:04:05"
|
|
DateLayout = "2006-01-02"
|
|
TimeLayoutMs = "2006-01-02 15:04:05.999"
|
|
)
|
|
|
|
func Now() time.Time {
|
|
return time.Now()
|
|
}
|
|
|
|
// FormatTime 格式化时间为标准字符串
|
|
func FormatTime(t time.Time) string {
|
|
return t.Format(TimeLayout)
|
|
}
|
|
|
|
// FormatTimeMs 格式化时间为毫秒精度字符串
|
|
func FormatTimeMs(t time.Time) string {
|
|
return t.Format(TimeLayoutMs)
|
|
}
|
|
|
|
// ParseTime 解析标准时间字符串
|
|
func ParseTime(s string) (time.Time, error) {
|
|
return time.ParseInLocation(TimeLayout, s, time.Local)
|
|
}
|
|
|