10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-11 16:43:39 +01:00
qmcchem/ocaml/Time.ml

51 lines
1.1 KiB
OCaml
Raw Normal View History

2019-07-19 11:46:29 +02:00
let of_sec s =
Unix.gmtime s
let to_sec t =
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
and mday = t.Unix.tm_mday
in
sec +
min * 60 +
hour * 60 * 60 +
2019-07-23 17:34:58 +02:00
(mday-1) * 60 * 60 * 24
2019-07-19 11:46:29 +02:00
let string_of_t t =
2019-07-23 17:34:58 +02:00
let mday = t.Unix.tm_mday - 1 in
2019-07-19 11:46:29 +02:00
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour + 24*mday
in
2019-07-23 17:34:58 +02:00
Printf.sprintf "%2d:%2.2d:%2.2d" hour min sec
2019-07-19 11:46:29 +02:00
2019-07-22 11:31:16 +02:00
let string_of_date t =
let year = 1900 + t.Unix.tm_year in
let mon = t.Unix.tm_mon in
let mday = t.Unix.tm_mday in
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
in
let month =
match mon with
| 0 -> "Jan" | 1 -> "Feb" | 2 -> "Mar" | 3 -> "Apr"
| 4 -> "May" | 5 -> "Jun" | 6 -> "Jul" | 7 -> "Aug"
| 8 -> "Sep" | 9 -> "Oct" | 10 -> "Nov" | 11 -> "Dec"
| _ -> assert false
in
2019-07-23 17:34:58 +02:00
Printf.sprintf "%2d %3s %4d - %2d:%2.2d:%2.2d" mday month year hour min sec
2019-07-22 11:31:16 +02:00
let string_of_now () =
2019-10-01 10:41:48 +02:00
Unix.gettimeofday ()
2019-07-22 11:31:16 +02:00
|> Unix.localtime
|> string_of_date
2019-07-19 11:46:29 +02:00
let string_of_sec s =
of_sec s
|> string_of_t