Roy
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2012
08:51 AM
How to generate an ISO-8601 string?
To work with an external API, I need to generate the current time as an ISO-8601 string. Is there an easy way to do this? roDateTime can *parse* an ISO-8601, but I don't see any way to generate one.
1 REPLY 1

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2012
09:44 PM
Re: How to generate an ISO-8601 string?
Function DateToISO8601String(date As Object, includeZ = True As Boolean) As String
iso8601 = PadLeft(date.GetYear().ToStr(), "0", 4)
iso8601 = iso8601 + "-"
iso8601 = iso8601 + PadLeft(date.GetMonth().ToStr(), "0", 2)
iso8601 = iso8601 + "-"
iso8601 = iso8601 + PadLeft(date.GetDayOfMonth().ToStr(), "0", 2)
iso8601 = iso8601 + "T"
iso8601 = iso8601 + PadLeft(date.GetHours().ToStr(), "0", 2)
iso8601 = iso8601 + ":"
iso8601 = iso8601 + PadLeft(date.GetMinutes().ToStr(), "0", 2)
iso8601 = iso8601 + ":"
iso8601 = iso8601 + PadLeft(date.GetSeconds().ToStr(), "0", 2)
If includeZ Then
iso8601 = iso8601 + "Z"
End If
Return iso8601
End Function
Function PadLeft(value As String, padChar As String, totalLength As Integer) As String
While value.Len() < totalLength
value = padChar + value
End While
Return value
End Function
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)