Skip to content

Latest commit

 

History

History

T

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

T

-- import "github.com/kokizzu/gotro/T"

Usage

const FILE = `20060102_150405`
const HMS = `150405`
const HUMAN = `2-Jan-2006 15:04:05`
const HUMAN_DATE = `2 Jan 2006`
const ISO = `2006-01-02T15:04:05.999999`
const YMD = `2006-01-02`
const YMDH = `20060102.15`
const YMDHM = `20060102.1504`
const YMD_HM = `2006-01-02 15:04`
const YMD_HMS = `2006-01-02 15:04:05`
const YY = `06`
var EMPTY = time.Time{}

func Age

func Age(birthdate time.Time) float64

Age returns age from current date

func AgeAt

func AgeAt(birthdate, point time.Time) float64

AgeAt returns age from within 2 date

func DateHhMmStr

func DateHhMmStr() string

DateHhMmStr current iso date and hour

T.DateHhMmStr()// output "20160317.1059"

func DateHhStr

func DateHhStr() string

DateHhStr current iso date and hour

T.DateHhStr()// output "20160317.10"

func DateStr

func DateStr() string

DateStr current iso date T.DateStr()) // "2016-03-17"

func DateTimeStr

func DateTimeStr() string

DateTimeStr current iso date and time

T.ToDateTimeStr(time.Now()) // "2016-03-17 10:07:50"

func DayInt

func DayInt() int64

DayInt int64 day of current date

func Epoch

func Epoch() int64

Epoch get current unix (second) as integer

func EpochAfter

func EpochAfter(d time.Duration) int64

EpochAfter get current unix time added with a duration

func EpochAfterStr

func EpochAfterStr(d time.Duration) string

EpochAfterStr get current unix time added with a duration

func EpochStr

func EpochStr() string

EpochStr get current unix (second) as string

func Filename

func Filename() string

Filename get filename version of current date

T.Filename()) // "20160317_102543"

func HhmmssStr

func HhmmssStr() string

HhmmssStr get filename version of current time

func HourInt

func HourInt() int64

HourInt int64 current hour

func HumanStr

func HumanStr() string

HumanStr current human date

T.HumanStr() // "17-Mar-2016 10:06"

func IsValidTimeRange

func IsValidTimeRange(start, end, check time.Time) bool

IsValidTimeRange check if time in are in the range

t1, _:=time.Parse(`1992-03-23`,T.DateFormat)
t2, _:=time.Parse(`2016-03-17`,T.DateFormat)
T.IsValidTimeRange(t1,t2,time.Now()) // bool(false)

func IsoStr

func IsoStr() string

IsoStr current iso time

T.IsoStr() // "2016-03-17T10:07:56.418728"

func LastTwoDigitYear

func LastTwoDigitYear() string

LastTwoDigitYear return current last two digit year

func MonthInt

func MonthInt() int64

MonthInt int64 current month

func RandomSleep

func RandomSleep()

RandomSleep random 0.4-2 sec sleep

func Sleep

func Sleep(ns time.Duration)

Sleep delay for nanosecond

func ToDateHourStr

func ToDateHourStr(t time.Time) string

ToDateHourStr convert time to iso date and hour:minute

T.ToDateHourStr(time.Now()) // "2016-03-17 10:07"

func ToDateStr

func ToDateStr(t time.Time) string

ToDateStr convert time to iso date

T.ToDateStr(time.Now()) // output "2016-03-17"

func ToDateTimeStr

func ToDateTimeStr(t time.Time) string

ToDateTimeStr convert time to iso date and time

T.ToDateTimeStr(time.Now()) // "2016-03-17 10:07:50"

func ToEpoch

func ToEpoch(date string) int64

ToEpoch convert string date to epoch => '2019-01-01' -->1546300800

func ToHhmmssStr

func ToHhmmssStr(t time.Time) string

ToHhmmssStr convert time to iso date and hourminutesecond

T.ToDateHourStr(time.Now()) // "230744"

func ToHumanStr

func ToHumanStr(t time.Time) string

ToHumanStr convert time to human date

T.ToHumanStr(time.Now()) // "17-Mar-2016 10:06"

func ToIsoStr

func ToIsoStr(t time.Time) string

ToIsoStr convert time to iso formatted time string

T.ToIsoStr(time.Now()) // "2016-03-17T10:04:50.6489"

func Track

func Track(fun func()) time.Duration

Track measure elapsed time in nanosec

T.Track(func(){
  x:=0
  T.Sleep(1)
}) // "done in 1.00s"

func UnixNano

func UnixNano() int64

UnixNano get current unix nano

func UnixNanoAfter

func UnixNanoAfter(d time.Duration) int64

UnixNanoAfter get current unix nano after added with certain duration

func UnixToDateStr

func UnixToDateStr(epoch float64) string

UnixToDateStr convert from unix sconds to YYYY-MM-DD

func UnixToDateTimeStr

func UnixToDateTimeStr(epoch float64) string

UnixToDateTimeStr convert unix seconds to YYYY-MM-DD_hh:mm:ss

func UnixToFile

func UnixToFile(i int64) string

UnixToFile convert unix time to file naming

func UnixToHumanDateStr

func UnixToHumanDateStr(epoch float64) string

UnixToHumanDateStr convert from unix to human date format D MMM YYYY

func UnixToHumanStr

func UnixToHumanStr(epoch float64) string

UnixToHumanStr convert from unix to human format D-MMM-YYYY hh:mm:ss

func Weekday

func Weekday() int

Weekday get what day is it today, Sunday => 0

func WeekdayStr

func WeekdayStr() string

WeekdayStr get day's name

func YearDayInt

func YearDayInt() int64

YearDayInt int64 current day of year

func YearInt

func YearInt() int64

YearInt int64 current year