How to convert a date and time to your timestamp, but not using os.time()
in Lua? What expression to calculate? Is it possible?
Example:
data = "01/01/2015"
hora = "10:00:00"
How to convert a date and time to your timestamp, but not using os.time()
in Lua? What expression to calculate? Is it possible?
Example:
data = "01/01/2015"
hora = "10:00:00"
Well, according to [ link ] there are several TimeStamp formats, if you already have the date information and time, as in the question, you can look for a format that fits that description. For example, ISO 8601 [ link ] defines that a date (day / month / year) should be represented as year -month-day, you could use the moon's string functions to separate the typed information and generate that Time Stamp. For example, suppose you implement a split function as described in [ link ], you could generate your TimeStamp like this:
data = "04/02/2016" --Quatro de Janeiro de 2016
dataTable = split(data,"/")
--timeStamp = 2016-02-04 (Conforme ISO 8601)
timeStamp = dataTable[1] .. "-" ..dataTable[2] .. "-" ..dataTable[3]
Same idea can be applied to add the hours, minutes and seconds. However, if you want a time stamp as it returns it for os.time () (Seconds since a certain date), it is strongly recommended to use a library, although it is possible to calculate, in a very rough way it would look like this: p>
anoZero=1960
ano=2016
mes = 2 + ((ano-anoZero)*12)
dias = 4 + (mes * 30) --Simplificação, o ideal seria calcular o numero de dias para cada mês
horas = 1 + (dias * 24)
minutos=29 + (horas*60)
segundos=minutos * 60 -- Numero de segundos desde 1960-01-01 00:00:00