[Solved] A different date format! lazarus / 21-General ---------------------------------------------------------------------- loaded · 2024-04-25 10:55 Hi All, I have a recipe format like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 2002-10-13T21:00:00.000Z I want to convert it to this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 14/10/2002Is it possible? ---------------------------------------------------------------------- cdbc · 2024-04-25 11:06 Hi Yes ofc, but that ISO datetime-stamp equals => UTC 13/10/2002 @ 9:00 PM So what exactly are you trying to achieve?!? The ISO format is dead-easy to parse  edit: Have a 'Sniff' around in the RTL there are some ISO routines lying around Regards Benny ---------------------------------------------------------------------- alpine · 2024-04-25 11:11 DateUtils have ISO8601ToDate function Then use FormatDateTime to convert the returned timestamp. Your result is one day ahead, do you mean it will be according to a different time zone? ---------------------------------------------------------------------- loaded · 2024-04-25 11:11 Thank you very much for your answer, cdbc. The information you provided is very useful to me, I didn't know this before. Because I haven't worked with dates before. Quote from: cdbc on April 25, 2024, 01:06:44 pmSo what exactly are you trying to achieve?!? I am trying to display the date 2002-10-13T21:00:00.000Z as 14/10/2002 and insert it into a json tree we have. ---------------------------------------------------------------------- cdbc · 2024-04-25 11:21 Hi @alpine remembered the function name in the RTL... QuoteYour result is one day ahead, do you mean it will be according to a different time zone?I'll re-ask his question?!? Regards Benny ---------------------------------------------------------------------- cdbc · 2024-04-25 11:24 Hi A little inspiration on working with string-dates:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  { time formats, used in bcstrtotime }  STRSHORT = 0; { StrShort }  STRLONG  = 1; { StrLong }  STRISO   = 2; { StrIso }  { date formats, used in bcdetectdateformat }  DATE_DA  = 0; { danish dd.mm.yyyy }  DATE_US  = 1; { us std. mm/dd/yyyy }  DATE_ISO = 2; { iso spec. yyyy- mm-dd }  DATE_STR = 3; { danish dd-mm-yyyy } ...{ bcStrToDate #2 takes 3 params, the string to convert, the  format ~ DATE_DA,  DATE_US & DATE_ISO and the type ~ STRSHORT, STRLONG & STRISO, returns a TDateTime }function bcStrToDate(const aDateStr: string; aFormat, aType: word): TDateTime;var  P,PE: pchar;  L,Fc,Y,M,D: word;  Buf: string;  C: char;begin  if aDateStr = '' then exit;  case aFormat of  DATE_DA : C:= '.';    DATE_US : C:= '/';    DATE_ISO: C:= '-';    DATE_STR: C:= '-'; { extra for numbnuts }  end;  L:= Length(aDateStr);  P:= pchar(aDateStr); PE:= P + L; Buf:= ''; Fc:= 0;  while P <= PE do begin    if ((P^ = C) or (P = PE)) then begin      case Fc of        0: begin             case aFormat of               DATE_DA,DATE_STR : D:= Buf.ToInteger;               DATE_US : M:= Buf.ToInteger;               DATE_ISO: Y:= Buf.ToInteger;             end;             Buf:= '';             inc(Fc); // 1           end; { Fc = 0 }        1: begin             case aFormat of               DATE_DA,DATE_STR : M:= Buf.ToInteger;               DATE_US : D:= Buf.ToInteger;               DATE_ISO: M:= Buf.ToInteger;             end;             Buf:= '';             inc(Fc); // 2           end; { Fc = 1 }        2: begin             case aFormat of               DATE_DA,DATE_STR : Y:= Buf.ToInteger;               DATE_US : Y:= Buf.ToInteger;               DATE_ISO: D:= Buf.ToInteger;             end;             Buf:= '';             inc(Fc); // 3           end; { Fc = 2 }      end; { case fc of }    end; { P^=C }    if P^ in ['0'..'9'] then Buf+= P^;    inc(P);  end; { while }  { cater for DATE_STR ~ NumbNuts using '-' in DATE_DA }  if aFormat = DATE_ISO then begin { iso or idiots at play }    if D > 31 then begin { idiots at play }      L:= Y;      Y:= D;  { switch'a'roo }      D:= L;    end;  end;  { cater for short dates }  if aType = STRSHORT then if Y < ((YearOf(now)-2000)+5) then Y+= 2000 else Y+= 1900; { lookahead = 5 years }  Result:= EncodeDate(Y,M,D);end; { bcStrToDate #2 }Regards Benny ---------------------------------------------------------------------- loaded · 2024-04-25 11:37 alpine, thank you very much for your answer. I never thought the history event would be this detailed. cdbc and alpine, I did some work with the information you gave me and got the result I wanted. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i showmessage (DateToStr(ISO8601ToDate('2002-10-13T21:00:00.000Z',false))); I'm glad to have you. Respects. ---------------------------------------------------------------------- alpine · 2024-04-25 11:49 @loaded Aware of time-zones! Your input is UTC, ISO8601ToDate will do a local TZ adjustment and may trip over midnight. And  DateToStr will work with your local format settings, may not be DD/MM/YY on a client computer. ---------------------------------------------------------------------- loaded · 2024-04-26 04:37 Thank you for the additional information, brother alpine.