12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package utils
- import (
- "time"
- )
- // ToDate 转化为日期
- func ToDate(second int64) string {
- return time.Unix(second, 0).Format(time.DateOnly)
- }
- // ToDateTime 转化为日期时间
- func ToDateTime(second int64) string {
- return time.Unix(second, 0).Format(time.DateTime)
- }
- // CurDate 获取当前日期
- func CurDate() string {
- return time.Now().Format(time.DateOnly)
- }
- // CurDateTime 获取当前日期时间
- func CurDateTime() string {
- return time.Now().Format(time.DateTime)
- }
- func ToSecond(date, layout string) int64 {
- dateTime, err := time.Parse(layout, date)
- if err != nil {
- return 0
- }
- return dateTime.Unix()
- }
- func DateAdd(date string, day int64) string {
- dateTime, err := time.Parse(time.DateOnly, date)
- if err != nil {
- return ""
- }
- return dateTime.Add(time.Duration(day) * 24 * time.Hour).Format(time.DateOnly)
- }
- func CurTimestamp() int64 {
- return time.Now().Unix()
- }
- // Second int64转换成秒类型
- func Second(s int64) time.Duration {
- return time.Duration(s) * time.Second
- }
|