Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


how to get UTC time and date from local time?

how to get UTC time and date from local time?

how to get UTC time and date from local time?


I'm falling over with this probably easy task.

I'm trying to get from the computer time, a time and date that is in UTC.

Time in format hh:mm (also in hh:mm:ss too)
Date in format yymmdd

I've tried adding ZoneInfo.Bias and ZoneInfo.DaylightBias to my time, but that gets some odd time that counts backwards.

Looking deeper, it seems I can use a function TzSpecificLocalTimeToSystemTime, but I don't get how to use that.
(SystemTime gives UTC all over world, yes?)

Would some kind soul put me out of my misery?

Steve (Delphi 2007 & XP)

RE: how to get UTC time and date from local time?

Open "Windows SDK" in Delphi Help. (aka "Win32 Developer's Reference")

In the index, browse to "System Time".  That page has several links.  One is the structure itself, "SYSTEMTIME".

I have a demo app somewhere in my archives that shows all you can do.  If I can find it, I'll post it for you.  In the mean-time (pun intended), that should keep you busy.

Chicago - Does anybody really know what time it is?

RE: how to get UTC time and date from local time?


I had found that in help, but I do have trouble interpreting the help into practical code with some of these functions.

I can't seem to see how to translate the info presented


typedef struct _SYSTEMTIME {  WORD wYear;  WORD wMonth;  WORD wDayOfWeek;  WORD wDay;  WORD wHour;  WORD wMinute;  WORD wSecond;  WORD wMilliseconds;
into something usable like this:


procedure TMainForm.TimeZoneClick(Sender: TObject);
  MyTime : TDateTime;
  UTC: TSystemTime;
  MyTime := Time;
  with Memo1.Lines do
    Add('PC time: '+TimeToStr(MyTime));
    Add('UTC: '+IntToStr(UTC.wHour)+':'+IntToStr(UTC.wMinute)+':'+IntToStr(UTC.wSecond));
    Add('Date: '+IntToStr(UTC.wYear)+':'+IntToStr(UTC.wMonth)+':'+IntToStr(UTC.wDay));

(I found something like the above to adapt to suit me with another go at google today using some different search terms.)

Steve (Delphi 2007 & XP)

RE: how to get UTC time and date from local time?


I can't seem to see how to translate the info presented...  CODE OMITTED ...into something usable like this:...  CODE OMITTED
Before explaining, let me ask this: Did your version of Delphi 7 include the RTL source code?

If "yes", right-click on "TSystemTime" in your code and select "Find Declaration".

If not, here is a what you'd see: (from ..\\delphi7\source\rtl\Win\Windows.pas


  { System time is represented with the following structure: }
  PSystemTime = ^TSystemTime;
  _SYSTEMTIME = record
    wYear: Word;
    wMonth: Word;
    wDayOfWeek: Word;
    wDay: Word;
    wHour: Word;
    wMinute: Word;
    wSecond: Word;
    wMilliseconds: Word;
  TSystemTime = _SYSTEMTIME;
As you can see, Delphi has done it for you.  Most all of Windows.pas is a wrapper around the Windows 32 API.
So, your code


fills all the UTC record fields as the strucure shows.  Use the DateTimeToSystemTime and SystemTimeToDateTime functions to convert between TSystemTime values and TDateTime values.


Delphi Rules!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close