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

No, but with little help from roRegEx.Match() it should be trivial.

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

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.

“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.