AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

UTC datetime string to TDateTime

Ein Thema von WojTec · begonnen am 24. Jan 2017 · letzter Beitrag vom 24. Jan 2017
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

UTC datetime string to TDateTime

  Alt 24. Jan 2017, 11:10
Delphi-Version: 10 Berlin
There is sample datetime string in UTC:

Code:
UTC 2011-02-05 21:25:55
Is it routine to convert it to TDateTime? Or I must do it manually?

Geändert von WojTec (24. Jan 2017 um 11:33 Uhr)
  Mit Zitat antworten Zitat
bra

Registriert seit: 20. Jan 2015
711 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#2

AW: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 11:37
You can use http://docwiki.embarcadero.com/Libra....ISO8601ToDate
There are a few other conversion functions in System.DateUtils that might be useful too.
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 11:40
This is two steps:
  1. Parsing the String into a TDateTime
  2. Converting the TDateTime in UTC timezone to your local timezone

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.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#4

Re: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 12:13
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)?
  Mit Zitat antworten Zitat
a.def
(Gast)

n/a Beiträge
 
#5

AW: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 13:49
Never in 2 lines. As already mentioned look here: How to convert to TDateTime an string formatted this way: 15h44m28s? [duplicate]
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#6

Re: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 15:34
Ok, thanks! Another question: how can I convert my datetime to ISO8601 with RegEx?
  Mit Zitat antworten Zitat
a.def
(Gast)

n/a Beiträge
 
#7

AW: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 15:42
Decode your TDateTime.

DecodeDate - Extracts the year, month, day values from a TDateTime var.
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#8

AW: UTC datetime string to TDateTime

  Alt 24. Jan 2017, 15:49
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
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:43 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