Forum

> > CS2D > Scripts > String to Epoch Returning nil.
Forums overviewCS2D overview Scripts overviewLog in to reply

English String to Epoch Returning nil.

3 replies
To the start Previous 1 Next To the start

old String to Epoch Returning nil.

Mami Tomoe
User Off Offline

Quote
Hi, I'm experimenting with some time/date functions and I've come acoss this strange issue:

The code:
1
2
3
4
5
function string_to_epoch(str)
	local t_hour, t_min, t_sec, t_day, t_month, t_year = str:match('(%d+):(%d+):(%d+) (%d+)/(%d+)/(%d+)')
	
	return os.time({ year = t_year, month = t_month, day = t_day, hour = t_hour, min = t_min, sec = t_sec, isdst = false })
end

The input:
1
'05:34:01 23/06/19'

The output:
nil


I've checked and the table does seem to contain the information it's supposed to.

old Re: String to Epoch Returning nil.

Baloon
GAME BANNED Off Offline

Quote
Try using
table.sort
?

1
return os.time(table.sort({ year = t_year, month = t_month, day = t_day, hour = t_hour, min = t_min, sec = t_sec, isdst = false }))
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview