Time formatting example
This is just silly example to fiddle with numbers and timestamps.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh time_format
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; time_format.ano
;
; To compile:
;
; $ ./build/ano ./examples/time_format/time_format.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME time_format
; @ANO_SCRIPT_VERSION 0.0.1
; @ANO_SCRIPT_DESCRIPTION Simple time/date conversion example
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; This is just silly example to fiddle with numbers and timestamps.
;
main [exit: 0] {
mov _birth ("1974-09-21")
; Get current time formatted as ISO-8601.
;
_t = time
_n = time_strfmt (\
time: _t, \
format: "%Y-%m-%dT%H:%M:%S")
print "This moment is: " . _n . "\n"
; Convert two timestamps to seconds since epoch…
;
_a = time_fmtstr (\
time: _n, \
format: "%Y-%m-%dT%H:%M:%S")
_b = time_fmtstr (\
time: _birth, \
format: "%Y-%m-%d")
; …get the difference in secs…
;
_c = time_diff (\
time_a: _a, \
time_b: _b)
; …and convert the difference into date.
;
_d = time_strfmt (\
time: _c, \
format: "%Y-%m-%dT%H:%M:%S")
print "Difference between " . _birth . " and this moment is " . _c . \
" seconds,\nas formatted date since system epoch: " . _d . "\n"
}
; ------------------------------------------------------------------------------ ; time_format.w2c ; ; To compile: ; ; $ ./build/widget ./examples/time_format/time_format.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; time_format.m2c ; ; To compile: ; ; $ ./build/menu ./examples/time_format/time_format.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.