Version française
Home     About     Download     Resources     Contact us    
Browse thread
Time stamp module floating around?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Time stamp module floating around?
On Sat, 2007-01-20 at 21:42 -0500, Denis Bueno wrote:
> I'm looking for simple bit of code that will print human-readable
> timestamps. Something suitable for a log file.

(*
Scrap used in Felix for lines like: 

//Timestamp: 2007/1/12 18:36:37 UTC
//Timestamp: 2007/1/13 5:36:37 (local)
*)


let tim() = 
  let now = (Unix.times()).Unix.tms_utime in
  let elapsed = now -. !last_time in
  last_time := now;
  elapsed
;;

let format_time tm = 
  si (tm.Unix.tm_year + 1900) ^ "/" ^
  si (tm.Unix.tm_mon + 1) ^ "/" ^
  si tm.Unix.tm_mday ^ " " ^
  si tm.Unix.tm_hour ^ ":" ^
  si tm.Unix.tm_min ^ ":" ^
  si tm.Unix.tm_sec 
;;
try
  (* Time initialisation *)
  let compile_start = Unix.time () in
  let compile_start_gm = Unix.gmtime compile_start in
  let compile_start_local = Unix.localtime compile_start in
  let compile_start_gm_string = format_time compile_start_gm ^ " UTC" in
  let compile_start_local_string = format_time compile_start_local ^
" (local)" in


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net