github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xtime/time.go (about)

     1  package xtime
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // UTC return utc time
     8  func UTC() time.Time {
     9  	return time.Now().In(time.UTC)
    10  }
    11  
    12  // Local return local time
    13  func Local() time.Time {
    14  	return time.Now()
    15  }
    16  
    17  // NowMillis return now time in milliseconds
    18  func NowMillis() int64 {
    19  	return time.Now().UnixNano() / 1e6
    20  }
    21  
    22  func Yesterday() time.Time {
    23  	return time.Now().AddDate(0, 0, -1)
    24  }
    25  
    26  func Tomorrow() time.Time {
    27  	return time.Now().AddDate(0, 0, 1)
    28  }
    29  
    30  func StartOfDay(t time.Time) time.Time {
    31  	year, month, day := t.Date()
    32  	return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
    33  }
    34  
    35  func EndOfDay(t time.Time) time.Time {
    36  	year, month, day := t.Date()
    37  	return time.Date(year, month, day, 23, 59, 59, 999999999, t.Location())
    38  }
    39  
    40  func StartOfToday() time.Time {
    41  	return StartOfDay(time.Now())
    42  }
    43  
    44  func EndOfToday() time.Time {
    45  	return EndOfDay(time.Now())
    46  }