Getting a UTC timestamp using DateTime

Hello, I am trying to get a UTC Unix Timestamp via DateTime. I know that ToUniversalTime returns a table, but how can I convert this into a proper Unix Timestamp? (or if there is a better way using DateTime to get a timestamp in UTC).

1 Like

os.time() os

2 Likes

Can I ask why you need the UTC timestamp specifically? There are other ways to represent a datetime

Also DateTimes have a property called UnixTimestamp which seems suspicious :slight_smile:

I misunderstood DateTime after trying to convert from using os.time(). I had assumed there was some arbitrary way to obtain UTC timestamps much like how you would use os.date("!*t").

Of course, DateTime being the recommended and newer alternative, this process is much more streamlined. The more detailed answer is that the way I had tried to convert :ToUniversalTime() to a Unix Timestamp was not the correct path, instead, it’s simpler to just use DateTime.now().UnixTimestamp.

Can I ask what the difference between this method and just using os.time() is?