xtime

package
v0.25.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

README

GoKit - xtime

Time kits for Golang development.

Installation

go get -u github.com/likexian/gokit

Importing

import (
    "github.com/likexian/gokit/xtime"
)

Documentation

Visit the docs on GoDoc

Example

Get current timestamp
// print as int64 unix timestamp, example: 1552314204
fmt.Println(xtime.S())

// print as int64 unix timestamp of millisecond, example: 1552314204000
fmt.Println(xtime.Ms())

// print as YYYY-MM-DD HH:II:SS
fmt.Println(xtime.String())
Time string to timestamp
// print as int64 unix timestamp
n, err := xtime.StrToTime("2019-03-11 22:23:24")
if err != nil {
    fmt.Println(n)
}
Timestamp to time string
// print as YYYY-MM-DD HH:II:SS
s := xtime.TimeToStr(1552314204)
if err != nil {
    fmt.Println(n)
}

License

Copyright 2012-2024 Li Kexian

Licensed under the Apache License 2.0

Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can give me a cup of coffee.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCanceled is canceled error
	ErrCanceled = errors.New("xtime: canceled")
	// ErrTimeouted is timeouted error
	ErrTimeouted = errors.New("xtime: timeouted")
)

Functions

func Author

func Author() string

Author returns package author

func License

func License() string

License returns package license

func Ms

func Ms() int64

Ms returns unix timestamp in Millisecond

func Now

func Now() time.Time

Now returns time.Now

func Ns

func Ns() int64

Ns returns unix timestamp in Nanosecond

func S

func S() int64

S returns unix timestamp in Second

func SetInterval

func SetInterval(fn TimeCallback, timeout time.Duration) (chan interface{}, func())

SetInterval execute the callback every timeout return a chan and cancel func

func SetTimeout

func SetTimeout(fn TimeCallback, timeout time.Duration) (chan interface{}, func())

SetTimeout execute the callback after timeout return a chan and cancel func

func Sleep

func Sleep(n int64)

Sleep n Second

func StrToTime

func StrToTime(s string, layout ...string) (int64, error)

StrToTime returns unix timestamp of time string

func String

func String() string

String returns string of now

func TimeToStr

func TimeToStr(n int64, layout ...string) string

TimeToStr returns time string of unix timestamp, format in time.Local

func Us

func Us() int64

Us returns unix timestamp in Microsecond

func Usleep

func Usleep(n int64)

Usleep n Microsecond

func Version

func Version() string

Version returns package version

func WithTimeout

func WithTimeout(fn TimeCallback, timeout time.Duration) (chan interface{}, func())

WithTimeout execute the callback with timeout return a chan and cancel func

Types

type TimeCallback

type TimeCallback func() interface{}

TimeCallback is a callback with one return value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL