1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package utils
- import (
- "strings"
- "time"
- "github.com/jinzhu/now"
- )
- const DateFormat = "2006-01-02"
- const DateTimeFormat = "2006-01-02 15:04:05"
- func GetBeginAndEndOfDay(date string) (begin, end int64, err error) {
- t, err := now.Parse(date) // 2017-10-13 00:00:00, nil
- if err != nil {
- return
- }
- begin = now.With(t).BeginningOfDay().Unix()
- end = now.With(t).EndOfDay().Unix()
- return
- }
- func Format(date time.Time) string {
- return date.Format("2006-01-02")
- }
- func FormatSecond(date time.Time) string {
- return date.Format("2006-01-02 15:04:05")
- }
- func ParseDate(date string) string {
- if i := strings.Index(date, "T"); i > 0 {
- return date[:i]
- }
- return date
- }
- func ParseDateToTime(date string) time.Time {
- return now.MustParse(ParseDate(date))
- }
- func ParseUnixStamp(date string) int64 {
- if i := strings.Index(date, "T"); i > 0 {
- return now.MustParse(date[:i]).Unix()
- }
- return 0
- }
- func GetYearDay2(tm *time.Time) int {
- return tm.Year()*1000 + tm.YearDay()
- }
|