Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
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.

Thanks

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
#1  
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?
PRO
USA
#2  
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.
PRO
USA
#3  
Script:

Code:


$MyDate=$date

$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)
$UnixTime=($diff_days*86400)+($diff_hours*3600)+($diff_minutes*60)+$diff_seconds
print("Human readable date: " + $MyDate)
print("Unix Epoch : " + $UnixTime)


online converter tool: https://www.epochconverter.com/

I had a deja vu moment... remember this thread:
https://www.ez-robot.com/Community/Forum/Thread?threadId=9760

Are you still playing with Dates ?:D
PRO
USA
#4  
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.
PRO
USA
#6  
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.
PRO
USA
#7  
@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.