Date and time format question

Bob Sneidar bobsneidar at iotecdigital.com
Mon Jul 29 18:14:31 EDT 2024


Simpler than that: 

on mouseUp
   put "Mon, 29 Jul 2024 15:49:52 -0400" into tDateTime
   put word -1 of tDateTime into tOffset
   -- delete last word of tDateTime
   convert tDateTime to seconds
   put (tOffset / 100) *60 *60 into tOffset
   add tOffset to tDateTime
   convert tDateTime to  long date and  long time
   put tDateTime
end mouseUp

Bob S


> On Jul 29, 2024, at 3:02 PM, Paul Dupuis via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> dateItems does not contain the timezone offset, so you would need to get the timezone offset from the internet date (the only format I can find that has it) and the break the offset into minutes and hours and perform the math.
> 
> I haven't tested this code (yet), but I think the seconds is the way to go.
> 
> function refiXMLTimestamp
>   -- Need to return the timestamp (current time) in UTC format, or YYYY-MM-DDTHH:MM:SSZ where Z is zulu or GMT
>   local tTimestamp
>   get the internet date -- Mon, 29 Jul 2024 16:49:52 -0400
>   -- the day of the week followed by a comma, all other item delimited by a space
>   -- the day of the month
>   -- the three-letter abbreviation for the month name
>   -- the four-digit year
>   -- the time in 24-hour format, including seconds, delimited by colons
>   -- the four-digit time zone relative to UTC (Greenwich) time
>   set the itemDel to space
>   put last item of it into tZoneOffset -- +/-hhmm
>   set the itemDel to comma
>   convert it to seconds
>   -- the year
>   -- the month number
>   -- the day of the month
>   -- the hour in 24-hour time
>   -- the minute
>   -- the second
>   -- the numeric day of the week where Sunday is day 1, Monday is day 2, and so forth
>   put    char -1 to -2 of tZoneOffset into tMinOffset
>   delete char -1 to -2 of tZoneOffset
>   put ((tZoneOffset*3600)+(tMinOffset*60)) into tSecOffset
>   -- adjust time to zulu/gmt
>   add tSecOffset to it
>   convert it to dateItems
>   -- Now convert to YYYY-MM-DDTHH:MM:SSZ where Z is zulu of GMT/UTC
>   put format("%4u",item 1 of it) &"-"& format("%2u",item 2 of it) &"-"& format("%2u",item 3 of it)           into tTimestamp -- the date in new format
>   put "T"& format(%2u",item 4 of it) &":"& format("%2u",item 5 of it) &":"& format("%2u",item 6 of it) &"Z" after tTimestamp -- the time in new format
>   return tTimestamp
> end refiXMLTimestamp
> 
> On 7/29/2024 5:37 PM, Bob Sneidar via use-livecode wrote:
>> Convert it to dateitems, then back again.
>> 
>> Bob S
>> 
>> 
>>> On Jul 29, 2024, at 2:09 PM, Paul Dupuis via use-livecode <use-livecode at lists.runrev.com> wrote:
>>> 
>>> Follow up question/request:
>>> 
>>> put the internet date into tTimestamp -- stores something like Mon, 29 Jul 2024 16:49:52 -0400, where the -0400 is the time zone offset
>>> 
>>> Anyone have some already written code to convert this to a time in GMT (i.e where the time zone offset is +0000, i.e. Mon, 29 Jul 2024 20:49:52 +0000)?
>>> 
>>> It is adding the offset to the hours and minutes, but you have to handle carry over, potentially adding or subtracting a day.
>>> 
>>> If the best approach converting to seconds and the doing the math and converting back? (I think this is the answer)
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list