Compare commits

...

13 Commits

Author SHA1 Message Date
dtapps 1b8a3a8b18 - 增加 `FormatFilter`
4 days ago
dtapps e25da0cbd4 - 增加 `ZhFormat`
2 months ago
dtapps aae4112b32 - 增加 `ToDateFormatTime` 方法
3 months ago
dtapps ca62634337 - 增加 `SetCurrentMillisecondUnix` 方法
5 months ago
李光春 d269b45582 - 增加[验证字符串是否为时间]方法
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 9f8bce0361 - update
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details
2 years ago
李光春 f7b17917ad - update
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 ea8772e0c7 - update
2 years ago
李光春 953848c8c8 - update
2 years ago
李光春 a157c5dfce - update
2 years ago
李光春 cf182d4ba5 update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2 years ago
李光春 5a0141f905 update
continuous-integration/drone/push Build is passing Details
2 years ago
李光春 5993168de6 add bson
2 years ago

@ -0,0 +1,17 @@
kind: pipeline
type: docker
name: clone
steps:
- name: Test
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -v ./...
- name: Benchmark
image: golang:1.18
commands:
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go test -bench=. -benchmem

1
.gitignore vendored

@ -4,3 +4,4 @@
.idea
.vscode
.log
go_mod.sh

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 茂名聚合科技有限公司
Copyright (c) 2018 李光春
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

@ -1,25 +1,33 @@
<h1>
<a href="https://www.dtapp.net/">Golang Time</a>
<a href="https://www.dtapp.net/">Golang</a>
</h1>
📦 Golang 时间组件
📦 Golang 时间
[comment]: <> (go)
[![godoc](https://pkg.go.dev/badge/github.com/dtapps/gotime?status.svg)](https://pkg.go.dev/github.com/dtapps/gotime)
[![goproxy.cn](https://goproxy.cn/stats/github.com/dtapps/gotime/badges/download-count.svg)](https://goproxy.cn/stats/github.com/dtapps/gotime)
[![goreportcard.com](https://goreportcard.com/badge/github.com/dtapps/gotime)](https://goreportcard.com/report/github.com/dtapps/gotime)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/github.com%2Fdtapps%2Fgotime)
[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gotime?status.svg)](https://pkg.go.dev/go.dtapp.net/gotime)
[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gotime/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gotime)
[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gotime)](https://goreportcard.com/report/go.dtapp.net/gotime)
[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net%2Fgotime)
#### 安装使用
#### 安装
```go
go get -v -u github.com/dtapps/gotime
```shell
go get -v -u go.dtapp.net/gotime@v1.0.9
```
#### 导入
#### 使用
```go
package main
import (
"github.com/dtapps/gotime"
"go.dtapp.net/gotime"
"testing"
)
// TestVerification 验证字符串是否为时间
func TestVerification(t *testing.T) {
t.Log(gotime.Verification("2022-02-05 00:00:00", gotime.DateTimeFormat))
}
```

@ -1,136 +0,0 @@
package gotime
import (
"testing"
)
func TestTime(t *testing.T) {
t.Log("今天此刻:", Current().Now())
t.Log("今天此刻格式化:", Current().Format())
t.Log("今天此刻日期:", Current().ToDateFormat())
t.Log("今天此刻时间:", Current().ToTimeFormat())
t.Log("今天此刻时间戳:", Current().Timestamp())
t.Log("今天此刻时间戳:", Current().TimestampWithSecond())
t.Log("今天毫秒级时间戳:", Current().TimestampWithMillisecond())
t.Log("今天微秒级时间戳:", Current().TimestampWithMicrosecond())
t.Log("今天纳秒级时间戳:", Current().TimestampWithNanosecond())
t.Log("昨天此刻:", Yesterday().Now())
t.Log("昨天此刻格式化:", Yesterday().Format())
t.Log("昨天此刻日期:", Yesterday().ToDateFormat())
t.Log("昨天此刻时间:", Yesterday().ToTimeFormat())
t.Log("昨天此刻时间戳:", Yesterday().Timestamp())
t.Log("昨天此刻时间戳:", Yesterday().TimestampWithSecond())
t.Log("昨天毫秒级时间戳:", Yesterday().TimestampWithMillisecond())
t.Log("昨天微秒级时间戳:", Yesterday().TimestampWithMicrosecond())
t.Log("昨天纳秒级时间戳:", Yesterday().TimestampWithNanosecond())
t.Log("明天此刻:", Tomorrow().Now())
t.Log("明天此刻格式化:", Tomorrow().Format())
t.Log("明天此刻日期:", Tomorrow().ToDateFormat())
t.Log("明天此刻时间:", Tomorrow().ToTimeFormat())
t.Log("明天此刻时间戳:", Tomorrow().Timestamp())
t.Log("明天此刻时间戳:", Tomorrow().TimestampWithSecond())
t.Log("明天毫秒级时间戳:", Tomorrow().TimestampWithMillisecond())
t.Log("明天微秒级时间戳:", Tomorrow().TimestampWithMicrosecond())
t.Log("明天纳秒级时间戳:", Tomorrow().TimestampWithNanosecond())
t.Log("本世纪开始时间:", Current().StartOfCentury().Format())
t.Log("本世纪结束时间:", Current().EndOfCentury().Format())
t.Log("本年代开始时间:", Current().StartOfDecade().Format())
t.Log("本年代结束时间:", Current().EndOfDecade().Format())
t.Log("本年开始时间:", Current().StartOfYear().Format())
t.Log("本年结束时间:", Current().EndOfYear().Format())
t.Log("本季度开始时间:", Current().StartOfQuarter().Format())
t.Log("本季度结束时间:", Current().EndOfQuarter().Format())
t.Log("本月开始时间:", Current().StartOfMonth().Format())
t.Log("本月结束时间:", Current().EndOfMonth().Format())
t.Log("7100秒前的时间", Current().BeforeSeconds(7100).Format())
t.Log("2小时前的时间", Current().BeforeHour(2).Format())
t.Log("7100秒后的时间", Current().AfterSeconds(7100).Format())
t.Log("2小时后的时间", Current().AfterHour(2).Format())
t.Log("相差多少小时(绝对值)", SetCurrentParse("2022-03-01T10:03:39+08:00").Format())
t.Log("相差多少小时(绝对值)", SetCurrentParse("2022-03-04T11:12:47+08:00").Format())
}
func TestDayStartOfEnd(t *testing.T) {
t.Log("当前时间:", Current().Format())
t.Log("今天开始时间:", Current().StartOfDay().Format())
t.Log("今天结束时间:", Current().EndOfDay().Format())
t.Log("当前时间戳:", Current().Timestamp())
t.Log("今天开始时间戳:", Current().StartOfDay().Timestamp())
t.Log("今天结束时间戳:", Current().EndOfDay().Timestamp())
t.Log("n天前时间", Current().BeforeDay(1).Format())
t.Log("n天前开始时间戳", Current().BeforeDay(1).StartOfDay().Format())
t.Log("n天前结束时间戳", Current().BeforeDay(1).EndOfDay().Format())
t.Log("n天后时间", Current().AfterDay(1).Format())
t.Log("n天后开始时间戳", Current().AfterDay(1).StartOfDay().Format())
t.Log("n天后结束时间戳", Current().AfterDay(1).EndOfDay().Format())
}
func TestDiff(t *testing.T) {
t.Log("相差多少分秒:", Current().DiffInSecond(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("相差多少分秒(绝对值)", Current().DiffInSecondWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("相差多少分钟:", Current().DiffInMinutes(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("相差多少分钟(绝对值)", Current().DiffInMinutesWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("相差多少小时:", Current().DiffInHour(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("相差多少小时(绝对值)", Current().DiffInHourWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time))
}
func TestUnix(t *testing.T) {
t.Log(SetCurrentUnix(1640067240).Format())
t.Log(Current().BeforeDay(3 - 2).StartOfDay().Format())
t.Log(Current().BeforeDay(3 - 1).EndOfDay().Format())
}
func Test2(t *testing.T) {
t.Log(Current().BeforeDay(1 + 1).Format())
t.Log(Current().BeforeDay(1).Format())
t.Log(Current().BeforeHour(24).Format())
t.Log(Current().Format())
}
func TestTaoBao(t *testing.T) {
i := 1
for {
if i > 3 {
break
}
t.Log(i)
t.Log(i * 24)
t.Log((i * 24) - 24)
t.Log(Current().BeforeHour(i * 24).Format())
t.Log(Current().BeforeHour((i * 24) - 24).Format())
i++
}
}
func TestMT(t *testing.T) {
day := 1
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())
day = 2
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())
day = 3
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())
}
func TestCompare(t *testing.T) {
t.Log("是否大于:", Current().Gt(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("是否小于:", Current().Lt(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("是否等于:", Current().Eq(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("是否不等于:", Current().Ne(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("是否大于等于:", Current().Gte(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log("是否小于等于:", Current().Lte(SetCurrentParse("2021-11-26 14:50:00").Time))
}

@ -0,0 +1,16 @@
package gotime
const (
DateTimeFormat = "2006-01-02 15:04:05"
DateTimeShrinkFormat = "2006-01-02 15:04"
DateFormat = "2006-01-02"
TimeFormat = "15:04:05"
)
const (
DateTimeZhFormat = "2006年01月02日 15点04分05秒"
DateTimeZhShrinkFormat = "2006年01月02日 15点04分"
DateZhFormat = "2006年01月02日"
TimeZhFormat = "15点04分05秒"
TimeZhShrinkFormat = "15点04分"
)

@ -0,0 +1,11 @@
package gotime
import "testing"
func TestZhFormat(t *testing.T) {
t.Log("DateTimeZhFormat", Current().SetFormat(DateTimeZhFormat))
t.Log("DateTimeZhShrinkFormat", Current().SetFormat(DateTimeZhShrinkFormat))
t.Log("DateZhFormat", Current().SetFormat(DateZhFormat))
t.Log("TimeZhFormat", Current().SetFormat(TimeZhFormat))
t.Log("TimeZhShrinkFormat", Current().SetFormat(TimeZhShrinkFormat))
}

@ -1,3 +1,3 @@
module github.com/dtapps/gotime
module go.dtapp.net/gotime
go 1.18
go 1.22

@ -13,9 +13,6 @@ const (
RFC1036Format = "Mon, 02 Jan 06 15:04:05 -0700"
RFC7231Format = "Mon, 02 Jan 2006 15:04:05 GMT"
DayDateTimeFormat = "Mon, Jan 2, 2006 3:04 PM"
DateTimeFormat = "2006-01-02 15:04:05"
DateFormat = "2006-01-02"
TimeFormat = "15:04:05"
ShortDateTimeFormat = "20060102150405"
ShortDateFormat = "20060102"
ShortTimeFormat = "150405"
@ -23,9 +20,8 @@ const (
// Pro 结构体
type Pro struct {
Time time.Time
loc *time.Location
Error error
Time time.Time
loc *time.Location
}
// NewPro 初始化结构体
@ -36,42 +32,42 @@ func NewPro() Pro {
}
// BeforeSeconds 获取n秒前的时间
func (p Pro) BeforeSeconds(seconds int) Pro {
func (p Pro) BeforeSeconds(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("-%ds", seconds))
p.Time = p.Time.Add(st)
return p
}
// AfterSeconds 获取n秒后的时间
func (p Pro) AfterSeconds(seconds int) Pro {
func (p Pro) AfterSeconds(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("+%ds", seconds))
p.Time = p.Time.Add(st)
return p
}
// BeforeMinute 获取n分钟前的时间
func (p Pro) BeforeMinute(seconds int) Pro {
func (p Pro) BeforeMinute(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("-%dm", seconds))
p.Time = p.Time.Add(st)
return p
}
// AfterMinute 获取n分钟后的时间
func (p Pro) AfterMinute(seconds int) Pro {
func (p Pro) AfterMinute(seconds int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("+%dm", seconds))
p.Time = p.Time.Add(st)
return p
}
// BeforeHour 获取n小时前的时间
func (p Pro) BeforeHour(hour int) Pro {
func (p Pro) BeforeHour(hour int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("-%dh", hour))
p.Time = p.Time.Add(st)
return p
}
// AfterHour 获取n小时后的时间
func (p Pro) AfterHour(hour int) Pro {
func (p Pro) AfterHour(hour int64) Pro {
st, _ := time.ParseDuration(fmt.Sprintf("+%dh", hour))
p.Time = p.Time.Add(st)
return p
@ -95,11 +91,11 @@ func (p Pro) SetFormat(layout string) string {
}
// Month 获取当前月
func (p Pro) Month() int {
func (p Pro) Month() int64 {
return p.MonthOfYear()
}
// MonthOfYear 获取本年的第几月
func (p Pro) MonthOfYear() int {
return int(p.Time.In(p.loc).Month())
func (p Pro) MonthOfYear() int64 {
return int64(p.Time.In(p.loc).Month())
}

@ -0,0 +1,138 @@
package gotime
import (
"testing"
)
func TestTime(t *testing.T) {
t.Log("今天此刻 Now", Current().Now())
t.Log("测试 SetFormat", Current().SetFormat("20060102150405"))
t.Log("今天此刻格式化 Format", Current().Format())
t.Log("今天此刻日期 ToDateFormat", Current().ToDateFormat())
t.Log("今天此刻日期 ToDateFormatTime", Current().ToDateFormatTime())
t.Log("今天此刻时间 ToTimeFormat", Current().ToTimeFormat())
t.Log("今天此刻时间戳 Timestamp", Current().Timestamp())
t.Log("今天此刻时间戳 TimestampWithSecond", Current().TimestampWithSecond())
t.Log("今天毫秒级时间戳 TimestampWithMillisecond", Current().TimestampWithMillisecond())
t.Log("今天微秒级时间戳 TimestampWithMicrosecond", Current().TimestampWithMicrosecond())
t.Log("今天纳秒级时间戳 TimestampWithNanosecond", Current().TimestampWithNanosecond())
t.Log("昨天此刻 Now", Yesterday().Now())
t.Log("昨天此刻格式化 Format", Yesterday().Format())
t.Log("昨天此刻日期 ToDateFormat", Yesterday().ToDateFormat())
t.Log("昨天此刻日期 ToDateFormatTime", Yesterday().ToDateFormatTime())
t.Log("昨天此刻时间 ToTimeFormat", Yesterday().ToTimeFormat())
t.Log("昨天此刻时间戳 Timestamp", Yesterday().Timestamp())
t.Log("昨天此刻时间戳 TimestampWithSecond", Yesterday().TimestampWithSecond())
t.Log("昨天毫秒级时间戳 TimestampWithMillisecond", Yesterday().TimestampWithMillisecond())
t.Log("昨天微秒级时间戳 TimestampWithMicrosecond", Yesterday().TimestampWithMicrosecond())
t.Log("昨天纳秒级时间戳 TimestampWithNanosecond", Yesterday().TimestampWithNanosecond())
t.Log("明天此刻 Now", Tomorrow().Now())
t.Log("明天此刻格式化 Format", Tomorrow().Format())
t.Log("明天此刻日期 ToDateFormat", Tomorrow().ToDateFormat())
t.Log("明天此刻日期 ToDateFormatTime", Tomorrow().ToDateFormatTime())
t.Log("明天此刻时间 ToTimeFormat", Tomorrow().ToTimeFormat())
t.Log("明天此刻时间戳 Timestamp", Tomorrow().Timestamp())
t.Log("明天此刻时间戳 TimestampWithSecond", Tomorrow().TimestampWithSecond())
t.Log("明天毫秒级时间戳 TimestampWithMillisecond", Tomorrow().TimestampWithMillisecond())
t.Log("明天微秒级时间戳 TimestampWithMicrosecond", Tomorrow().TimestampWithMicrosecond())
t.Log("明天纳秒级时间戳 TimestampWithNanosecond", Tomorrow().TimestampWithNanosecond())
t.Log("本世纪开始时间:", Current().StartOfCentury().Format())
t.Log("本世纪结束时间:", Current().EndOfCentury().Format())
t.Log("本年代开始时间:", Current().StartOfDecade().Format())
t.Log("本年代结束时间:", Current().EndOfDecade().Format())
t.Log("本年开始时间:", Current().StartOfYear().Format())
t.Log("本年结束时间:", Current().EndOfYear().Format())
t.Log("本季度开始时间:", Current().StartOfQuarter().Format())
t.Log("本季度结束时间:", Current().EndOfQuarter().Format())
t.Log("本月开始时间:", Current().StartOfMonth().Format())
t.Log("本月结束时间:", Current().EndOfMonth().Format())
//t.Log("7100秒前的时间", Current().BeforeSeconds(7100).Format())
//t.Log("2小时前的时间", Current().BeforeHour(2).Format())
//t.Log("7100秒后的时间", Current().AfterSeconds(7100).Format())
//t.Log("2小时后的时间", Current().AfterHour(2).Format())
}
func TestStartOfDay(t *testing.T) {
t.Log(Current().Format())
t.Log(Current().StartOfDay().Format())
t.Log(Current().EndOfDay().Format())
t.Log(Current().Timestamp())
t.Log(Current().StartOfDay().Timestamp())
t.Log(Current().EndOfDay().Timestamp())
t.Log(Current().BeforeDay(1).Format())
t.Log(Current().BeforeDay(1).StartOfDay().Format())
t.Log(Current().BeforeDay(1).EndOfDay().Format())
t.Log(Current().AfterDay(1).Format())
t.Log(Current().AfterDay(1).StartOfDay().Format())
t.Log(Current().AfterDay(1).EndOfDay().Format())
}
func TestDiff(t *testing.T) {
t.Log(Current().DiffInHourWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log(Current().DiffInHour(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log(Current().DiffInMinutesWithAbs(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log(Current().DiffInMinutes(SetCurrentParse("2021-11-26 14:50:00").Time))
t.Log(SetCurrentParse("2022-03-01T10:03:39+08:00").Format())
t.Log(SetCurrentParse("2022-03-04T11:12:47+08:00").Format())
}
func TestUnix(t *testing.T) {
t.Log(SetCurrentUnix(1640067240).Format())
t.Log(Current().BeforeDay(3 - 2).StartOfDay().Format())
t.Log(Current().BeforeDay(3 - 1).EndOfDay().Format())
}
func Test2(t *testing.T) {
t.Log(Current().BeforeDay(1 + 1).Format())
t.Log(Current().BeforeDay(1).Format())
t.Log(Current().BeforeHour(24).Format())
t.Log(Current().Format())
}
func TestGt(t *testing.T) {
t.Log(SetCurrentParse("2022-07-29 15:05:24").Time)
t.Log(Current().Lte(SetCurrentParse("2022-07-18 17:05:24").Time))
}
func TestCompare(t *testing.T) {
t.Log("是否大于", Current().Gt(SetCurrentParse("2022-07-29 14:35:24").Time))
t.Log("是否小于", Current().Lt(SetCurrentParse("2022-07-29 14:35:24").Time))
}
func TestTaoBao(t *testing.T) {
var i int64 = 1
for {
if i > 3 {
break
}
t.Log(i)
t.Log(i * 24)
t.Log((i * 24) - 24)
t.Log(Current().BeforeHour(i * 24).Format())
t.Log(Current().BeforeHour((i * 24) - 24).Format())
i++
}
}
func TestMT(t *testing.T) {
var day int64 = 1
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())
day = 2
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())
day = 3
t.Log(day)
t.Log(Current().BeforeHour(24 * day).Format())
t.Log(Current().BeforeHour(24 * (day - 1)).Format())
}

@ -0,0 +1,6 @@
package gotime
// Bson mongoDB
func (p Pro) Bson() string {
return p.Now().String()
}

@ -9,15 +9,18 @@ import (
// Current 获取当前的时间
func Current() Pro {
var err error
p := NewPro()
p.loc, p.Error = time.LoadLocation("Asia/Shanghai")
if p.Error != nil {
// Docker部署golang应用时时区问题 https://www.ddhigh.com/2018/03/01/golang-docker-timezone.html
log.Printf("【gotime】时区错误%v\n", p.Error)
p.loc, err = time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Printf("【gotime】时区错误%v\n", err)
p.Time = time.Now().Add(time.Hour * 8)
} else {
p.Time = time.Now().In(p.loc)
}
return p
}
@ -31,9 +34,14 @@ func SetCurrent(sTime time.Time) Pro {
// SetCurrentParse 设置当前的时间
func SetCurrentParse(str string) Pro {
var err error
p := NewPro()
p.loc, p.Error = time.LoadLocation("Asia/Shanghai")
p.loc, err = time.LoadLocation("Asia/Shanghai")
if err != nil {
log.Printf("【gotime】时区错误%v\n", err)
p.Time = time.Now().Add(time.Hour * 8)
}
layout := DateTimeFormat
if str == "" || str == "0" || str == "0000-00-00 00:00:00" || str == "0000-00-00" || str == "00:00:00" {
@ -66,6 +74,13 @@ func SetCurrentUnix(ts int64) Pro {
return p
}
// SetCurrentMillisecondUnix 设置当前的时间 毫秒Unix时间戳
func SetCurrentMillisecondUnix(ts int64) Pro {
p := NewPro()
p.Time = time.Unix(ts/1000, 0)
return p
}
// Now 今天此刻
func (p Pro) Now() time.Time {
return p.Time
@ -76,11 +91,25 @@ func (p Pro) Format() string {
return p.Time.Format(DateTimeFormat)
}
// FormatFilter 今天此刻格式化 带 过滤无效时间
func (p Pro) FormatFilter() string {
if p.Time.Format(DateTimeFormat) == "0001-01-01 00:00:00" || p.Time.Format(DateTimeFormat) == "0001-01-01 08:05:43" {
return ""
} else {
return p.Time.Format(DateTimeFormat)
}
}
// ToDateFormat 今天此刻日期
func (p Pro) ToDateFormat() string {
return p.Time.Format(DateFormat)
}
// ToDateFormatTime 今天此刻日期
func (p Pro) ToDateFormatTime() time.Time {
return SetCurrentParse(p.Time.Format(DateFormat)).Time
}
// ToTimeFormat 今天此刻时间
func (p Pro) ToTimeFormat() string {
return p.Time.Format(TimeFormat)

@ -0,0 +1,16 @@
package gotime
import "time"
// Verification 验证字符串是否为时间
func Verification(str, layout string) (resp time.Time, err error) {
loc, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
return time.Time{}, err
}
location, err := time.ParseInLocation(layout, str, loc)
if err != nil {
return time.Time{}, err
}
return location, nil
}

@ -0,0 +1,7 @@
package gotime
import "testing"
func TestVerification(t *testing.T) {
t.Log(Verification("2022-02-05 00:00:00", DateTimeFormat))
}

@ -0,0 +1,3 @@
package gotime
const Version = "1.0.9"

@ -0,0 +1,13 @@
package gotime
import "testing"
func TestVersion(t *testing.T) {
t.Log(Version)
}
func BenchmarkVersion(b *testing.B) {
for i := 0; i < b.N; i++ {
b.Log(Version)
}
}
Loading…
Cancel
Save