Hello! Hopefully simple question today that I’m surprised I’ve not seen anywhere.
Is there a fundamentally different use case for the DateTime library vs. the os library?
I know they do slightly different things (e.g. DateTime.now() includes milliseconds), but I don’t see an overarching difference between them. What gives?
They are very similar, true.
os is a library built into normal non-roblox lua and I believe has been a part of roblox for longer than DateTime. The os.clock function is a lightweight method for benchmarking code at the microsecond level.
DateTime is a roblox-specific API. Notably, it adds millisecond precision to dates (compared to os.date which is second precision) and the ability to convert to/from ISO 8601 date string easily. It also has a friendlier interface in general, I think.
Basically, I’d probably use os.clock for benchmarking, the microprofiler for detailed performance analysis, and DateTime for everything else.
6 Likes