Skip to content

Instantly share code, notes, and snippets.

@fenix-hub
Last active February 11, 2022 19:21
Show Gist options
  • Save fenix-hub/cec77254b07eccf4e89af1456454f87e to your computer and use it in GitHub Desktop.
Save fenix-hub/cec77254b07eccf4e89af1456454f87e to your computer and use it in GitHub Desktop.
Converts an ISO 8601 Date String to UNIX Timestamp int
# The best option is always to confront dates based on their UNIX value
# With these scripts, you'll get something like "16778909182". Put it in the Array and sort it with the others.
var timestamp: String = "2021-08-04T16:45:35.603Z"
# Using String, Arrays and Dictionary
var datetime: PoolStringArray = timestamp.split("T")
var date: PoolStringArray = datetime[0].split("-")
var time: PoolStrngArray = datetime[1].split(":")
var unix_timestamp: int = OS.get_unix_time_from_datetime({year=date[0],month=date[1],day=date[2],hour=time[0],minute=time[1],second=time[2].substr(0,2)}
# Using RegEx
var regex: RegEx = RegEx.new()
regex.compile("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\.(\\d{3})Z")
var result: RegExMatch = regex.search(timestamp)
var unix_timestamp: int = OS.get_unix_time_from_datetime({year=result.get_string(0),month=result.get_string(1),day=result.get_string(2),hour=result.get_string(3),minute=result.get_string(4),second=int(result.get_string(5))+int(int(result.get_string(6))/1000))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment