Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Roy
Visitor

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 1
TheEndless
Channel Surfer

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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.