Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to display current date and time in UTC format? 2

Status
Not open for further replies.

doctorjellybean

Programmer
May 5, 2003
145
I need to obtain the current date and time in UTC (ISO 8601 extended) format to save it to a file like this:

"2013-02-02T11:25:17Z"

Would like the complete code (I do apologize for this, but my knowledge of this kind of programming is virtually zero [blush] ), e.g. a Button1OnClick event.

Thank you in advance.
 
Something like this:

var
myDate : TDateTime;

begin
myDate := StrToDateTime('02/06/2013 08:15');
ShowMessage('Date & Time = ' +DateTimeToStr(myDate));
end;
 
Sorry, missed the formatting [blush]
Code:
[b]var[/b]
  myDate : TDateTime;
  
[b]begin[/b]
  myDate := StrToDateTime([teal]'02/06/2013 08:15'[/teal]);
  ShowMessage([teal]'Date & Time = '[/teal] +DateTimeToStr(myDate));
[b]end[/b];
 
Thank you.

However, I need to display it like this:

2013-02-02T11:25:17Z
 
One thing to watch out for: 'Now' is local time and not your time converted to UTC. You have to be mindful of time zones and daylight savings time shifts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top