Is there a easy way to convert a (human readable) date to a unix timestamp OR better to direct calculate the time difference (in seconds) between 2 difference dates?
For example i have a date (stored) in format os.date(“%X”) and i want to caculate how much seconds it isbetween the actual current date/time: NOW().
In php i could use strotime, but is this also possible in lua and how?
os.time gives me a unixtimestamp, that is not human readable
I want to store a readble timestamp in a variable container and use this on a later time to determine if a scene must be run or not by caculating the difference between the stored timestamp and current timestamp.
At the moment i do this by using a unixtimestamp, problem here is a user cannot read/see what the exact time was when looking…
So i am looking to store a readable timestamp and use this to calculate the seconds between current timestamp.
I looked at os.time, but cannot find how, if you are sure this is possible do you have an example?
In order to calculate the difference between two times you need to express them both in an arithmetic type (i.e., a Unix-epoch integer) and then do a subtraction. The function that converts a decomposed time (year/month/date/hour/minute/second) to an epoch time is os.time. The function takes a single table argument, representing the decomposed time. If you omit the argument then the implied time is now. This latter use of os.time() is so common that people forget the single-argument usage. Take a look at the link in my previous post for examples.
If you’ve got a string that contains a human-readable datestamp then first you’ll have to use string.match() to break it up into components and tonumber() to convert the fragments into numbers.
Edit: … and then populate a table with those numbers, and pass that table to os.time() to get a Unix-epoch number that you can do arithmetic on.
I’m typing this on my phone so I’m not in a position to write code, but there’s your basic algorithm.
Best Home Automation shopping experience. Shop at Ezlo!