Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 7

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.
0 Kudos
1 Reply
Level 9

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)
0 Kudos