mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-11 16:22:26 +08:00
feat: add GetTodayStartTime and GetTodayEndTime
This commit is contained in:
@@ -96,6 +96,18 @@ func GetNowDateTime() string {
|
|||||||
return time.Now().Format("2006-01-02 15:04:05")
|
return time.Now().Format("2006-01-02 15:04:05")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTodayStartTime return the start time of today, format: yyyy-mm-dd 00:00:00.
|
||||||
|
// Play: todo
|
||||||
|
func GetTodayStartTime() string {
|
||||||
|
return time.Now().Format("2006-01-02") + " 00:00:00"
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTodayEndTime return the end time of today, format: yyyy-mm-dd 23:59:59.
|
||||||
|
// Play: todo
|
||||||
|
func GetTodayEndTime() string {
|
||||||
|
return time.Now().Format("2006-01-02") + " 23:59:59"
|
||||||
|
}
|
||||||
|
|
||||||
// GetZeroHourTimestamp return timestamp of zero hour (timestamp of 00:00).
|
// GetZeroHourTimestamp return timestamp of zero hour (timestamp of 00:00).
|
||||||
// Play: https://go.dev/play/p/QmL2oIaGE3q
|
// Play: https://go.dev/play/p/QmL2oIaGE3q
|
||||||
func GetZeroHourTimestamp() int64 {
|
func GetZeroHourTimestamp() int64 {
|
||||||
|
|||||||
@@ -91,6 +91,18 @@ func TestGetNowDateTime(t *testing.T) {
|
|||||||
assert.Equal(expected, GetNowDateTime())
|
assert.Equal(expected, GetNowDateTime())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetTodayStartTime(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestGetTodayStartTime")
|
||||||
|
expected := time.Now().Format("2006-01-02") + " 00:00:00"
|
||||||
|
assert.Equal(expected, GetTodayStartTime())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetTodayEndTime(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestGetTodayEndTime")
|
||||||
|
expected := time.Now().Format("2006-01-02") + " 23:59:59"
|
||||||
|
assert.Equal(expected, GetTodayEndTime())
|
||||||
|
}
|
||||||
|
|
||||||
func TestFormatTimeToStr(t *testing.T) {
|
func TestFormatTimeToStr(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestFormatTimeToStr")
|
assert := internal.NewAssert(t, "TestFormatTimeToStr")
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ import (
|
|||||||
- [GetNowDate](#GetNowDate)
|
- [GetNowDate](#GetNowDate)
|
||||||
- [GetNowTime](#GetNowTime)
|
- [GetNowTime](#GetNowTime)
|
||||||
- [GetNowDateTime](#GetNowDateTime)
|
- [GetNowDateTime](#GetNowDateTime)
|
||||||
|
- [GetTodayStartTime](#GetTodayStartTime)
|
||||||
|
- [GetTodayEndTime](#GetTodayEndTime)
|
||||||
- [GetZeroHourTimestamp](#GetZeroHourTimestamp)
|
- [GetZeroHourTimestamp](#GetZeroHourTimestamp)
|
||||||
- [GetNightTimestamp](#GetNightTimestamp)
|
- [GetNightTimestamp](#GetNightTimestamp)
|
||||||
- [FormatTimeToStr](#FormatTimeToStr)
|
- [FormatTimeToStr](#FormatTimeToStr)
|
||||||
@@ -643,14 +645,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
currentDate := datetime.GetNowDate()
|
currentDate := datetime.GetNowDate()
|
||||||
|
|
||||||
fmt.Println(currentDate)
|
fmt.Println(currentDate)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -675,14 +674,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
currentTime := datetime.GetNowTime()
|
currentTime := datetime.GetNowTime()
|
||||||
|
|
||||||
fmt.Println(currentTime) // 15:57:33
|
fmt.Println(currentTime) // 15:57:33
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -707,14 +703,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
current := datetime.GetNowDateTime()
|
current := datetime.GetNowDateTime()
|
||||||
|
|
||||||
fmt.Println(current)
|
fmt.Println(current)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -722,6 +715,64 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="GetTodayStartTime">GetTodayStartTime</span>
|
||||||
|
|
||||||
|
<p>Return the start time of today, format: yyyy-mm-dd 00:00:00.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GetTodayStartTime() string
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
startTime := datetime.GetTodayStartTime()
|
||||||
|
fmt.Println(startTime)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 2023-06-29 00:00:00
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="GetTodayEndTime">GetTodayEndTime</span>
|
||||||
|
|
||||||
|
<p>Return the end time of today, format: yyyy-mm-dd 23:59:59.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GetTodayEndTime() string
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
endTime := datetime.GetTodayEndTime()
|
||||||
|
fmt.Println(endTime)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 2023-06-29 23:59:59
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### <span id="GetZeroHourTimestamp">GetZeroHourTimestamp</span>
|
### <span id="GetZeroHourTimestamp">GetZeroHourTimestamp</span>
|
||||||
|
|
||||||
<p>Return timestamp of zero hour (timestamp of 00:00).</p>
|
<p>Return timestamp of zero hour (timestamp of 00:00).</p>
|
||||||
@@ -739,14 +790,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
zeroTime := datetime.GetZeroHourTimestamp()
|
zeroTime := datetime.GetZeroHourTimestamp()
|
||||||
|
|
||||||
fmt.Println(zeroTime)
|
fmt.Println(zeroTime)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -771,14 +819,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
nightTime := datetime.GetNightTimestamp()
|
nightTime := datetime.GetNightTimestamp()
|
||||||
|
|
||||||
fmt.Println(nightTime)
|
fmt.Println(nightTime)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ import (
|
|||||||
- [GetNowDate](#GetNowDate)
|
- [GetNowDate](#GetNowDate)
|
||||||
- [GetNowTime](#GetNowTime)
|
- [GetNowTime](#GetNowTime)
|
||||||
- [GetNowDateTime](#GetNowDateTime)
|
- [GetNowDateTime](#GetNowDateTime)
|
||||||
|
- [GetTodayStartTime](#GetTodayStartTime)
|
||||||
|
- [GetTodayEndTime](#GetTodayEndTime)
|
||||||
- [GetZeroHourTimestamp](#GetZeroHourTimestamp)
|
- [GetZeroHourTimestamp](#GetZeroHourTimestamp)
|
||||||
- [GetNightTimestamp](#GetNightTimestamp)
|
- [GetNightTimestamp](#GetNightTimestamp)
|
||||||
- [FormatTimeToStr](#FormatTimeToStr)
|
- [FormatTimeToStr](#FormatTimeToStr)
|
||||||
@@ -643,14 +645,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
currentDate := datetime.GetNowDate()
|
currentDate := datetime.GetNowDate()
|
||||||
|
|
||||||
fmt.Println(currentDate)
|
fmt.Println(currentDate)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -675,15 +674,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
currentTime := datetime.GetNowTime()
|
currentTime := datetime.GetNowTime()
|
||||||
|
fmt.Println(currentTime)
|
||||||
fmt.Println(currentTime) // 15:57:33
|
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 15:57:33
|
// 15:57:33
|
||||||
@@ -707,14 +703,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
current := datetime.GetNowDateTime()
|
current := datetime.GetNowDateTime()
|
||||||
|
|
||||||
fmt.Println(current)
|
fmt.Println(current)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -722,6 +715,64 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="GetTodayStartTime">GetTodayStartTime</span>
|
||||||
|
|
||||||
|
<p>返回当天开始时间, 格式: yyyy-mm-dd 00:00:00.</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GetTodayStartTime() string
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
startTime := datetime.GetTodayStartTime()
|
||||||
|
fmt.Println(startTime)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 2023-06-29 00:00:00
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="GetTodayEndTime">GetTodayEndTime</span>
|
||||||
|
|
||||||
|
<p>返回当天结束时间,格式: yyyy-mm-dd 23:59:59.</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func GetTodayEndTime() string
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
endTime := datetime.GetTodayEndTime()
|
||||||
|
fmt.Println(endTime)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 2023-06-29 23:59:59
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### <span id="GetZeroHourTimestamp">GetZeroHourTimestamp</span>
|
### <span id="GetZeroHourTimestamp">GetZeroHourTimestamp</span>
|
||||||
|
|
||||||
<p>获取零点时间戳(timestamp of 00:00)</p>
|
<p>获取零点时间戳(timestamp of 00:00)</p>
|
||||||
@@ -739,14 +790,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
zeroTime := datetime.GetZeroHourTimestamp()
|
zeroTime := datetime.GetZeroHourTimestamp()
|
||||||
|
|
||||||
fmt.Println(zeroTime)
|
fmt.Println(zeroTime)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
@@ -771,14 +819,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
|
||||||
nightTime := datetime.GetNightTimestamp()
|
nightTime := datetime.GetNightTimestamp()
|
||||||
|
|
||||||
fmt.Println(nightTime)
|
fmt.Println(nightTime)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
|
|||||||
Reference in New Issue
Block a user