1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package mhayaTime
- import (
- "time"
- cstring "github.com/mhaya/extend/string"
- )
- // ToSecond 输出秒级时间戳
- func (c MhayaTime) ToSecond() int64 {
- return c.Unix()
- }
- // ToMillisecond 输出毫秒级时间戳
- func (c MhayaTime) ToMillisecond() int64 {
- return c.Time.UnixNano() / int64(time.Millisecond)
- }
- func (c MhayaTime) ToMillisecondString() string {
- t := c.ToMillisecond()
- return cstring.ToString(t)
- }
- // ToMicrosecond 输出微秒级时间戳
- func (c MhayaTime) ToMicrosecond() int64 {
- return c.UnixNano() / int64(time.Microsecond)
- }
- // ToNanosecond 输出纳秒级时间戳
- func (c MhayaTime) ToNanosecond() int64 {
- return c.UnixNano()
- }
- // ToDateMillisecondFormat 2023-04-10 12:26:57.420
- func (c MhayaTime) ToDateMillisecondFormat() string {
- return c.Format(DateTimeMillisecondFormat)
- }
- // ToDateTimeFormat 2006-01-02 15:04:05
- func (c MhayaTime) ToDateTimeFormat() string {
- return c.Format(DateTimeFormat)
- }
- // ToDateFormat 2006-01-02
- func (c MhayaTime) ToDateFormat() string {
- return c.Format(DateFormat)
- }
- // ToTimeFormat 15:04:05
- func (c MhayaTime) ToTimeFormat() string {
- return c.Format(TimeFormat)
- }
- // ToShortDateTimeFormat 20060102150405
- func (c MhayaTime) ToShortDateTimeFormat() string {
- return c.Format(ShortDateTimeFormat)
- }
- // ToShortDateFormat 20060102
- func (c MhayaTime) ToShortDateFormat() string {
- return c.Format(ShortDateFormat)
- }
- // ToShortIntDateFormat 20060102
- func (c MhayaTime) ToShortIntDateFormat() int32 {
- strDate := c.ToShortDateFormat()
- intDate, _ := cstring.ToInt32(strDate)
- return intDate
- }
- // ToShortTimeFormat 150405
- func (c MhayaTime) ToShortTimeFormat() string {
- return c.Format(ShortTimeFormat)
- }
|