Asked — Edited

Unix Time

Looking for script code that will convert current time to Unix time. Unix time starts on 01/01/1970. I need to know how to calculate the Unix time for current time.



Upgrade to ARC Pro

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.


What you are speaking of is actually know as The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for 'Unix time'. Many Unix systems store epoch dates as a signed 32-bit integer.

Is that right?


I am trying to calculate the Unix Epoch time for now. Which is at this very moment, 1521648159. But cant get it to work via script.




$UnixEpoch = "01/01/1970 0:00:00 AM"
$diff = CDateTime($MyDate) - CDateTime($UnixEpoch)
$diff_days_hours = Split($diff, ":", 0)
$diff_days = Split($diff_days_hours, ".", 0)
$diff_hours = Split($diff_days_hours, ".", 1)
$diff_minutes = Split($diff, ":", 1)
$diff_seconds = Split($diff, ":", 2)
print("Human readable date: " + $MyDate)
print("Unix Epoch         : " + $UnixTime)

online converter tool:

I had a deja vu moment... remember this thread:

Are you still playing with Dates ?:D


Absolutely. Reviewed and tried may times, but couldn't get the calculated time to equal the actual UNIX Epoch time, was off by about 15 hours. Not sure why.

will try the example above and see how it does, appreciate the reminder.


Have to adjust for UTC, but I also was making a mistake in my days to hours calc. I couldnt find it since my error was 15 hours and not 24 so I spent my time looking at the hours and seconds calc. Sometimes cant see the Forest cause of the trees.

Thanks, working now.

Believe me I reviewed all my past time posts before posting this because I know how beat up I was going to get.

Really appreciate the assistance.


@dbeard: UnixEpoch is a sequencial time line (seconds since 1970), there is no concept of timezones, UTC date time is used to be immune to the Daylight savings and creating calculating issues.

Also is interesting to notice that many *nix servers can go years without a reboot, so UnixEpoch makes the life easier to count or compare different time moments.