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: 
joetesta
Roku Guru

Any way to convert from Date String?

Is there any easy way to convert a date from a format such as "Tue, 17 May 2016 18:26:28 GMT" to an ISO8601 string?
I don't see it here: https://sdkdocs.roku.com/display/sdkdoc/ifDateTime#ifDateTime-ToISOString()asString
wanted to ask before I try to create a function to do this; thank you in advance.

-Joe
aspiring
0 Kudos
4 REPLIES 4
EnTerr
Roku Guru

Re: Any way to convert from Date String?

No, but with little help from roRegEx.Match() it should be trivial.
0 Kudos
joetesta
Roku Guru

Re: Any way to convert from Date String?

yep thanks, i did this yesterday, sharing for posterity


r = CreateObject("roRegex", "...,\s(\d{1,2})\s([\S]+)\s(\d{4})\s([\S]+)\s.*","")
dateMatch = r.Match(hdrs.date)
if (dateMatch.Count() > 4)
' convert text month to numeric
mymonth = getNumericMonth(dateMatch[2])
if (mymonth <> invalid)
datetimestr = dateMatch[3] + "-" + mymonth + "-" + dateMatch[1] + "T" + dateMatch[4] + "z"
end if
end if


and my function to convert the name of the month:
function getNumericMonth(month as string)
abbrvmonth = Lcase(month.Left(3))
if (abbrvmonth = "jan")
returnmonth = "01"
elseif (abbrvmonth = "feb")
returnmonth = "02"
elseif (abbrvmonth = "mar")
returnmonth = "03"
elseif (abbrvmonth = "apr")
returnmonth = "04"
elseif (abbrvmonth = "may")
returnmonth = "05"
elseif (abbrvmonth = "jun")
returnmonth = "06"
elseif (abbrvmonth = "jul")
returnmonth = "07"
elseif (abbrvmonth = "aug")
returnmonth = "08"
elseif (abbrvmonth = "sep")
returnmonth = "09"
elseif (abbrvmonth = "oct")
returnmonth = "10"
elseif (abbrvmonth = "nov")
returnmonth = "11"
elseif (abbrvmonth = "dec")
returnmonth = "12"
end if
return returnmonth
end function
aspiring
0 Kudos
EnTerr
Roku Guru

Re: Any way to convert from Date String?

Let me promote a great feature of B/S:

BrightScript Debugger> month2num = {Jan: "01", Feb: "02", Mar: "03", Apr: "04", May: "05", Jun: "06", Jul: "07", Aug: "08", Sep: "09", Oct: "10", Nov: "11", Dec: "12"}

BrightScript Debugger> ? month2num.may, month2num["JUN"]
05 06

Also it's faster than an if-ladder.
0 Kudos
joetesta
Roku Guru

Re: Any way to convert from Date String?

"EnTerr" wrote:
Let me promote a great feature of B/S:
Also it's faster than an if-ladder.


Thanks EnTerr! After I posted that I was thinking there's got to be a better way.
aspiring
0 Kudos