Skip to main content

Time Methods

Time Methods apply to FPL time objects

Format

  • Format(layout)

Add

  • Add(relativeTime)

Before

  • Before(time)
    • return true or false

After

  • After(time)
    • return true or false

Round

  • Round(duration)
    • Round returns the result of rounding to the nearest multiple of dration. The rounding behavior for halfway values is to round up
    • Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

Unix

  • Unix()
    • return epoch time in second

UnixMilli

  • UnixMilli()
    • return epoch time in millisecond
let t = new Time()
printf("%s", t) // 2023-08-17T23:41:37-04:00
let t2 = t.Add("-1h")
printf("%s", t2) // 2023-08-17T22:41:37-04:00
printf("%d", t.Unix()) // 1692330097
printf("%d", t2.UnixMilli()) // 1692326497260
printf("%v", t2.Before(t)) // true
printf("%s", t2.Format("2006-01-02T15:04:05Z07:00"))
// 2023-08-17T22:41:37-04:00
printf("%s", t2.Round("1h")) // 2023-08-17T23:00:00-04:00