get current time and convert it to string

Abby (J.P.) the.ueabraham at laposte.net
Thu Apr 27 07:37:28 PDT 2006


Stewart Gordon wrote:
> Abby (J.P.) wrote:
> <snip>
>> Thanks, it works fine.
>> By the way, is there a way to set the time shifting used for the function
>> std.date.UTCtoLocalTime(long t); ?
>> It does automatically put me at GMT+4, and that's not valid.
> <snip>
> 
> It seems that either:
> - your computer is misconfigured
> - there's a bug somewhere in Phobos
> - there's a bug somewhere in your code
> 
> Looking at your headers of your posts, you appear to be in GMT+2 and 
> using Windows, but is this the same system that you're programming on? 
> Otherwise, which OS is it happening in?
> 
> Please post a complete code sample that demonstrates it.
> 
> Stewart.
I'm programming on WindowsXP home. The time (the clock on my tackbar) is 
set on GMT+1 (I live in France), but I also use the auto adjusting for 
summer time and winter time (so I'm GMT+1 during the winter, and GMT+2 
during summer). So it looks like my system is well configured.
Code example:

import std.c.time;
import std.date;
int main(char[][] args)
{
     char[] thetime = toTimeString(UTCtoLocalTime(getUTCtime()));
     printf("Local time: " ~ thetime);
     char[] thetime2 = toTimeString(getUTCtime());
     printf("\nUTC time: " ~ thetime2);
     return 0;
}

Output:
Local time: 18:34:33 GMT+0200
UTC time: 16:34:33 GMT+0200
Press any key to continue.

(It is now 16h35, so the Local time is shift from +2 hours)

--
Abby



More information about the Digitalmars-d-learn mailing list