Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle date and time in ocaml

Tags:

date

time

ocaml

Is there a way to handle date and time, some sort of module, in ocaml ? Vanilla ocaml i mean, so no OPAM, or this kind of things ?

It seems like there is nothing about it on the internet, i would have expected more docs for the OCaml langage, it's so frustrating...

I need it to do operations on date and time, transform date and times into seconds from epoch, and reverse it, ect...

If there is no way i will do my own functions, but if there is something already done in OCaml for that that would be way better !

like image 248
xoxel Avatar asked Oct 12 '25 11:10

xoxel


1 Answers

OCaml Unix library provides the interface to standard POSIX date/time functions such as time, mktime, gmtime, and localtime. They should be sufficient for your task. See the standard OCaml documentation for futher information.

Also, long time ago I wrote a small library that depends purely on the Unix module, and implements a few useful time transformations. I never published it, but feel free to grab the code, or use it as a set of examples.

And of course, there are plenty of libraries available in OPAM, or via a package manager of your operating system. It is always better, to reuse existing code, rather then duplicate it.

like image 150
ivg Avatar answered Oct 16 '25 02:10

ivg