1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package datetime
- import (
- "fmt"
- "time"
- )
- func Time() int64 {
- return time.Now().Unix()
- }
- func StrToTime(timeStr, layout string) (int64, error) {
- t, err := time.Parse(layout, timeStr)
- if err != nil {
- return 0, err
- }
- return t.Unix(), nil
- }
- func Date(timestamp int64, layout string) string {
- return time.Unix(timestamp, 0).Format(layout)
- }
- func CheckDate(month, day, year uint) bool {
- layout := "2006-01-02"
- timeStr := fmt.Sprintf("%d-%02d-%02d", year, month, day)
- _, err := time.Parse(layout, timeStr)
- if err != nil {
- return false
- }
- return true
- }
- func Sleep(seconds int64) {
- time.Sleep(time.Duration(seconds) * time.Second)
- }
- func Usleep(microseconds int64) {
- time.Sleep(time.Duration(microseconds) * time.Microsecond)
- }
|