Delphi-Version: 10 Berlin
UTC datetime string to TDateTime
There is sample datetime string in UTC:
Code:
Is it routine to convert it to TDateTime? Or I must do it manually?
UTC 2011-02-05 21:25:55
|
AW: UTC datetime string to TDateTime
You can use http://docwiki.embarcadero.com/Libra....ISO8601ToDate
There are a few other conversion functions in System.DateUtils that might be useful too. |
AW: UTC datetime string to TDateTime
This is two steps:
For Task 1, there is already a built-in routine if the String is a timestamp in ISO8601 format: ISO8601ToDate(..). This method can also automatically take care of converting to your local timezone or return UTC timezone. But your example is not. A valid ISO8601 timestamp would look like "2011-02-05T21:25:55Z" If you're out of luck regarding ISO8601, I'd use regular expressions. |
Re: UTC datetime string to TDateTime
Thank you guys! I did it classically (with lenght/pos/delete). Using RegEx will be better (for sure will be very simple, in two lines)?
|
AW: UTC datetime string to TDateTime
Never in 2 lines. As already mentioned look here: How to convert to TDateTime an string formatted this way: 15h44m28s? [duplicate]
|
Re: UTC datetime string to TDateTime
Ok, thanks! Another question: how can I convert my datetime to ISO8601 with RegEx?
|
AW: UTC datetime string to TDateTime
|
AW: UTC datetime string to TDateTime
You don't need regular expressions if you just want to get the ISO8601 representation of a TDateTime. There's already a built-in DateToISO8601(..) method for that :-)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:15 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz