parsing date time "2012-09-21T00:00:00"

I am getting the a date and time stamp from the server like “2012-09-21T00:00:00”. What is the best approach to parse it display in a human readable format. The SDK didn’t point me to an obvious method.

Thanks [import]uid: 108070 topic_id: 30454 reply_id: 330454[/import]

Yea, Lua’s date/time features are not the best in the world, but luckily it’s easy to parse.

local dateString = "2012-09-21T00:00:00"  
local dt = string.gmatch(dateString, "(%d)\-(%d)\-(%d)T(%d):(%d):(%d)[\+\-](%d)")  

at that point dt[1] = the year, dt[2] = the month, etc. If you want to have this as a table that can be fed back to os.time(), you would just want to make a new table

local t = {}  
t.year = dt[1]  
t.month = dt[2]  
t.day = dt[3]  
t.hour = dt[4]  
t.min = dt[5]  
t.sec = dt[6]  

[import]uid: 19626 topic_id: 30454 reply_id: 122019[/import]

thanks, i will try this :slight_smile: [import]uid: 108070 topic_id: 30454 reply_id: 122021[/import]

Yea, Lua’s date/time features are not the best in the world, but luckily it’s easy to parse.

local dateString = "2012-09-21T00:00:00"  
local dt = string.gmatch(dateString, "(%d)\-(%d)\-(%d)T(%d):(%d):(%d)[\+\-](%d)")  

at that point dt[1] = the year, dt[2] = the month, etc. If you want to have this as a table that can be fed back to os.time(), you would just want to make a new table

local t = {}  
t.year = dt[1]  
t.month = dt[2]  
t.day = dt[3]  
t.hour = dt[4]  
t.min = dt[5]  
t.sec = dt[6]  

[import]uid: 19626 topic_id: 30454 reply_id: 122019[/import]

thanks, i will try this :slight_smile: [import]uid: 108070 topic_id: 30454 reply_id: 122021[/import]