time.c (548B)
1 #include <u.h> 2 #include <libc.h> 3 #include <venti.h> 4 5 int 6 vttimefmt(Fmt *fmt) 7 { 8 vlong ns; 9 Tm tm; 10 11 if(fmt->flags&FmtSign){ 12 ns = va_arg(fmt->args, long); 13 ns *= 1000000000; 14 } else 15 ns = nsec(); 16 tm = *localtime(ns/1000000000); 17 if(fmt->flags&FmtLong){ 18 return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d.%03d", 19 tm.year+1900, tm.mon+1, tm.mday, 20 tm.hour, tm.min, tm.sec, 21 (int)(ns%1000000000)/1000000); 22 }else{ 23 return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d", 24 tm.year+1900, tm.mon+1, tm.mday, 25 tm.hour, tm.min, tm.sec); 26 } 27 }