Vijay
Vijay

Reputation: 420

How to get date from string with this format yyyy-MM-dd'T'HH:mm:ss.SSSZZZ in lua script

How to get os.time from the data string with this format yyyy-MM-dd'T'HH:mm:ss.SSSZZZ and I will do some calculations to get date after number of days from the above date, but I need to get the resultant date also in this format yyyy-MM-dd'T'HH:mm:ss.SSSZZZ

I am able to do the calculations but the only issue is in need to read the date with the above format and return the date in the same format.

 now = os.time{year = yearValue, month = monthValue, day = dayValue, hour = hourValue, min = minutesValue}

 numberOfDays = now + 2 * 24 * 3600 -- here 2 is the number of days
print(os.date("%c",numberOfDays)) -- number of days returns the date after give number of days

Can anyone help me with the date format(yyyy-MM-dd'T'HH:mm:ss.SSSZZZ) that i should read and return. Thanks in advance

Upvotes: 1

Views: 3355

Answers (1)

Ivo
Ivo

Reputation: 23357

print(os.date("%Y-%m-%dT%H:%m:%S.000 %z",numberOfDays))

I think this is the closest you can get. milliseconds is hardcoded 000 because there are no milliseconds in lua and the timezone is like +0100 for example. reference to date formatting used in lua: http://www.cplusplus.com/reference/ctime/strftime/

Upvotes: 3

Related Questions