local Time <-> UTC 
Author Message
 local Time <-> UTC

Quote:

>Can any body tell me how can I convert from a local time to a UTC time and
>backwards in Win95? The time can be anywhere from 1900 to 2999.

Perhaps I'm missing something obvious, but why not just add or subtract the
time difference?

Chris
-----------------------------------------------------------------------

Visit our web site at http://www.*-*-*.com/
Astronomy software written by astronomers, for astronomers



Wed, 07 Feb 2001 03:00:00 GMT  
 local Time <-> UTC
Hi

I never do that on Win95, but I do the following on NT (using filetimes 64
bits long).

....
SystemTimeToFileTime (...);
LocalFileTimeToFileTime (...);

I hope it helps you

Regards
                                                    Jean-Paul



Wed, 07 Feb 2001 03:00:00 GMT  
 local Time <-> UTC

Quote:

>Use SystemTimeToFileTime() to get a FILETIME structure with the UTC time,
>the call FileTimeToLocalFileTime() to get a FILETIME structure in local
>time, and then use FileTimeToSystemTime() to get a SYSTEMTIME structure
with
>the local time.

Isn't this simply a "long winded" equivalent to calling "GetLocalTime?

Chris
-----------------------------------------------------------------------

Visit our web site at http://www.skymap.com
Astronomy software written by astronomers, for astronomers



Thu, 08 Feb 2001 03:00:00 GMT  
 local Time <-> UTC
No. The original question is how to convert an _arbitrary_ local time to
it's UTC equivalent and back, not how to get the _currrnt_ local time.

--
Tomas Restrepo

http://www.geocities.com/SiliconValley/Heights/3401


Quote:

>Isn't this simply a "long winded" equivalent to calling "GetLocalTime?

>Chris
>-----------------------------------------------------------------------

>Visit our web site at http://www.skymap.com
>Astronomy software written by astronomers, for astronomers



Thu, 08 Feb 2001 03:00:00 GMT  
 local Time <-> UTC
I did it this way:
1. Convert the date to a Julian day, using the routine in the Forth
Scientific Library, and the time to seconds since midnight (you're supposed
to use noon with Julian days, but I'm not an astronomer).
2. Subtract the base offset.
3. Take the year of the date I'm converting and the start/end dates in
TZInfo and figure out what the nth Sunday is that year.
4. Compare the two start/end dates with the result of step 2 and determine
whether DST is in effect at that time.
5. Subtract either the standard offset or the daylight offset.

Note: A Julian date on top of a time of day will compare correctly with D<
, but takes a 1440 /MOD operation on the time of day when adding or
subtracting.

The reverse routine, which I haven't written yet, will be similar, but
remember that there is one hour in the year which could be either standard
or daylight. Also make sure it works in a southern hemisphere time zone.

phma


Quote:
> Can any body tell me how can I convert from a local time to a UTC time
and
> backwards in Win95? The time can be anywhere from 1900 to 2999.

> SystemTimeToTzSpecificLocalTime does not work in Win95 and I could not
find
> any other function to do the job.



Thu, 08 Feb 2001 03:00:00 GMT  
 local Time <-> UTC

Quote:

> I did it this way:
> 1. Convert the date to a Julian day, using the routine in the Forth
> Scientific Library, and the time to seconds since midnight (you're supposed
> to use noon with Julian days, but I'm not an astronomer).
> 2. Subtract the base offset.
> 3. Take the year of the date I'm converting and the start/end dates in
> TZInfo and figure out what the nth Sunday is that year.
> 4. Compare the two start/end dates with the result of step 2 and determine
> whether DST is in effect at that time.
> 5. Subtract either the standard offset or the daylight offset.

Just to save you some time, here's the routines I use for julian/date
conversions (based on the algorithm by Fliegel & Van Flander):

const long      DateToJulian(const int y, const int m, const int d)
{
        /* obs: only valid with dates 01/03/-4800 onward */
        return (1461 * (y + 4800 + (m - 14) / 12)) / 4 +
                (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 -
                (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 +
                d - 32075;

Quote:
}

void    JulianToDate(const long jd, int *const y, int *const m,
                 int *const d)
{
        /* obs: only valid with dates 01/03/-4900 onward */
        int             l = jd + 68569;
        int             n = (4 * l) / 146097;
        int             i, j;

        l -= ((146097 * n + 3) / 4);
        i = (4000 * (l + l)) / 1461001;
        l -= ((1461 * i) / 4 + 31);
        j = (80 * l) / 2447;
        *d = l - (2447 * j) / 80;       /* day */
        l = j / 11;
        *m = j + 2 - (12 * l);          /* month */
        *y = 100 * (n - 49) + i + l;    /* year */

Quote:
}

These assume >= 32-bit int. If your system has >= 32-bit longs but not
ints, change ints to longs and put an extra L after numeric values to
make them long constants.

Since the original Julian dates do not have times, neither do these
routines. The time system was added by astronomers to have an easy way
for counting times. They use 12pm (or noon) to be the start of the day,
because the night thus falls nicely into one day, and represent times as
fractions of the day (noon = .0, 6am = .25, midday = .50 and 6pm = .75,
for example).

HTH,
        AriL
--
*DO NOT* send me email unless I ask you to.
I read the answers where I ask the questions.
This may also help some other people.



Sun, 11 Feb 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. local Time <-> UTC

2. How to convert local time with specific time zone to UTC time in Win32 API

3. Converting UTC time to local time

4. converting from Local Time to UTC time...

5. <<<<<<<Parsing help, please>>>>>>>>

6. converting UTC to local time

7. File Format conversion, ascii freeform -->.csv <-->.wk1<-->dbf<-->?HELP

8. <<<>>>Need C code advice with functions and sorting.<<<>>>

9. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

10. >>>Windows Service<<<

11. How to convert local time to gmt using a local variable time zone per process/thread

12. UTC time from time server

 

 
Powered by phpBB® Forum Software