From 388171e739eb4cad3d0be1700df85f15adf35f09 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Tue, 30 May 2023 17:47:16 +0800 Subject: [PATCH] doc: add doc for BetweenSeconds --- docs/datetime.md | 39 +++++++++++++++++++++++++++++++++++++++ docs/datetime_zh-CN.md | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/docs/datetime.md b/docs/datetime.md index f221a40..ca9bf6f 100644 --- a/docs/datetime.md +++ b/docs/datetime.md @@ -55,6 +55,7 @@ import ( - [ToFormatForTpl](#ToFormatForTpl) - [ToIso8601](#ToIso8601) - [IsLeapYear](#IsLeapYear) +- [BetweenSeconds](#BetweenSeconds)
@@ -1136,3 +1137,41 @@ func main() { // false } ``` + + +### BetweenSeconds + +

Return the number of seconds between two times.

+ +Signature: + +```go +func BetweenSeconds(t1 time.Time, t2 time.Time) int64 +``` + +Example: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/datetime" +) + +func main() { + today := time.Now() + tomorrow := AddDay(today, 1) + yesterday := AddDay(today, -1) + + result1 := datetime.BetweenSeconds(today, tomorrow) + result2 := datetime.BetweenSeconds(today, yesterday) + + fmt.Println(result1) + fmt.Println(result2) + + // Output: + // 86400 + // -86400 +} +``` diff --git a/docs/datetime_zh-CN.md b/docs/datetime_zh-CN.md index 1d5a1bc..09e6330 100644 --- a/docs/datetime_zh-CN.md +++ b/docs/datetime_zh-CN.md @@ -54,6 +54,8 @@ import ( - [ToFormatForTpl](#ToFormatForTpl) - [ToIso8601](#ToIso8601) - [IsLeapYear](#IsLeapYear) +- [BetweenSeconds](#BetweenSeconds) +
@@ -1135,3 +1137,40 @@ func main() { // false } ``` + +### BetweenSeconds + +

返回两个时间的间隔秒数。

+ +函数签名: + +```go +func BetweenSeconds(t1 time.Time, t2 time.Time) int64 +``` + +示例: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/datetime" +) + +func main() { + today := time.Now() + tomorrow := AddDay(today, 1) + yesterday := AddDay(today, -1) + + result1 := datetime.BetweenSeconds(today, tomorrow) + result2 := datetime.BetweenSeconds(today, yesterday) + + fmt.Println(result1) + fmt.Println(result2) + + // Output: + // 86400 + // -86400 +} +```