timeutil

package
v12.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 7 Imported by: 46

Documentation

Overview

Package timeutil provides methods for working with time

Index

Examples

Constants

This section is empty.

Variables

View Source
var StartDate = uint32(1322611200)

StartDate contains start date timestamp

Functions

func DurationToSeconds

func DurationToSeconds(d time.Duration) int64

DurationToSeconds converts duration to seconds

Example
fmt.Println(DurationToSeconds(time.Minute))
Output:

60

func Format

func Format(d time.Time, f string) string

Format returns formatted date as a string

Interpreted sequences:

'%%' a literal %
'%a' locale's abbreviated weekday name (e.g., Sun)
'%A' locale's full weekday name (e.g., Sunday)
'%b' locale's abbreviated month name (e.g., Jan)
'%B' locale's full month name (e.g., January)
'%c' locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
'%C' century; like %Y, except omit last two digits (e.g., 20)
'%d' day of month (e.g, 01)
'%D' date; same as %m/%d/%y
'%e' day of month, space padded
'%F' full date; same as %Y-%m-%d
'%g' last two digits of year of ISO week number (see %G)
'%G' year of ISO week number (see %V); normally useful only with %V
'%h' same as %b
'%H' hour (00..23)
'%I' hour (01..12)
'%j' day of year (001..366)
'%k' hour ( 0..23)
'%K' milliseconds (000..999)
'%l' hour ( 1..12)
'%m' month (01..12)
'%M' minute (00..59)
'%n' a newline
'%N' nanoseconds (000000000..999999999)
'%p' AM or PM
'%P' like %p, but lower case
'%r' locale's 12-hour clock time (e.g., 11:11:04 PM)
'%R' 24-hour hour and minute; same as %H:%M
'%s' seconds since 1970-01-01 00:00:00 UTC
'%S' second (00..60)
'%t' a tab
'%T' time; same as %H:%M:%S
'%u' day of week (1..7); 1 is Monday
'%U' week number of year, with Sunday as first day of week (00..53)
'%V' ISO week number, with Monday as first day of week (01..53)
'%w' day of week (0..6); 0 is Sunday
'%W' week number of year, with Monday as first day of week (00..53)
'%x' locale's date representation (e.g., 12/31/99)
'%X' locale's time representation (e.g., 23:13:48)
'%y' last two digits of year (00..99)
'%Y' year
'%z' +hhmm numeric timezone (e.g., -0400)
'%:z' +hh:mm numeric timezone (e.g., -04:00)
'%Z' alphabetic time zone abbreviation (e.g., EDT)
Example
date := time.Date(2010, 6, 15, 15, 30, 45, 1234, time.Local)

fmt.Println(Format(date, "%A %d/%b/%Y %H:%M:%S.%N"))
Output:

Tuesday 15/Jun/2010 15:30:45.000001234

func ParseDuration

func ParseDuration(dur string) int64

ParseDuration parses duration in 1w2d3h5m6s format and return as seconds

Example
fmt.Println(ParseDuration("2w3d10h20m35s"))
fmt.Println(PrettyDuration(ParseDuration("2w3d10h20m35s")))
Output:

1506035
2 weeks 3 days 10 hours 20 minutes and 35 seconds

func PrettyDuration

func PrettyDuration(d interface{}) string

PrettyDuration returns pretty duration (e.g. 1 hour 45 seconds)

Example
// you can use int ...
fmt.Println(PrettyDuration(300))

// ... and time.Duration types
fmt.Println(PrettyDuration(123456 * time.Second))
Output:

5 minutes
1 day 10 hours 17 minutes and 36 seconds

func ShortDuration

func ShortDuration(d interface{}) string

ShortDuration returns pretty short duration (e.g. 1:37)

Types

type Date

type Date uint32

Date is tiny date

func TinyDate

func TinyDate(t int64) Date

TinyDate creates tiny date struct by timestamp

func (Date) Time

func (d Date) Time() time.Time

Time returns time struct

func (Date) Unix

func (d Date) Unix() int64

Unix returns unix timestamp

Jump to

Keyboard shortcuts

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