Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UTC to Local Time
Message
 
To
12/02/2014 13:08:35
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP3
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01594152
Message ID:
01594517
Views:
32
I've been out of work since last Thursday - sorry.

Thanks for the info !

I'll try this code out and see how it goes!

>>Thanks for the info, Rick.
>>If you get time, I'd appreciate you taking the time to code this.
>>Thanks a bunch.
>>Tommy
>
>This seems to work. Please report any bugs. The "System Time" references below are Windows-speak for UTC times.
>
>
LOCAL lcTz, lcLocal, lcSystem, lnResult, ltDateTime
>LOCAL lnYearL, lnMonthL, lnDowL, lnDayL, lnHourL, lnMinL, lnSecL, lnMsecL
>LOCAL lnYearS, lnMonthS, lnDowS, lnDayS, lnHourS, lnMinS, lnSecS, lnMsecS
>
>
>**********
>* Declare functions
>*****
>    DECLARE INTEGER GetTimeZoneInformation          IN kernel32.dll STRING@ cTz172
>    DECLARE INTEGER SystemTimeToTzSpecificLocalTime IN kernel32.dll STRING  cTz172, STRING cSystem16, STRING@ cLocal16
>    DECLARE INTEGER TzSpecificLocalTimeToSystemTime IN kernel32.dll STRING  cTz172, STRING cLocal16,  STRING@ cSystem16
>    DECLARE INTEGER GetSystemTime                   IN kernel32.dll STRING@ cSystem16
>    DECLARE INTEGER GetLocalTime                    IN kernel32.dll STRING@ cLocal16
>
>
>**********
>* Grab the current time
>*****
>    lcLocal     = SPACE(16)
>    lcSystem    = SPACE(16)
>    GetLocalTime(@lcLocal)
>    GetSystemTime(@lcSystem)
>
>
>**********
>* Break out the values within
>*****
>SET STEP ON
>    extract_time(lcLocal,  @lnYearL, @lnMonthL, @lnDowL, @lnDayL, @lnHourL, @lnMinL, @lnSecL, @lnMsecL)
>    extract_time(lcSystem, @lnYearS, @lnMonthS, @lnDowS, @lnDayS, @lnHourS, @lnMinS, @lnSecS, @lnMsecS)
>
>
>**********
>* Get the time zone
>*****
>    lcTz        = SPACE(172)
>    lnResult    = GetTimeZoneInformation(@lcTz)
>    DO CASE
>        CASE lnResult = 0
>            * Unknown, error
>        CASE lnResult = 1
>            * Standard
>        CASE lnResult = 2
>            * Daylight savings
>    ENDCASE
>
>
>**********
>* Convert local to system time
>*****
>    lcLocalToSystem  = SPACE(16)
>    TzSpecificLocalTimeToSystemTime(lcTz, lcLocal, @lcLocalToSystem)
>SET STEP ON
>    extract_time(lcLocalToSystem, @lnYearS, @lnMonthS, @lnDowS, @lnDayS, @lnHourS, @lnMinS, @lnSecS, @lnMsecS)
>
>
>**********
>* Convert system to local time
>******
>    lcSystemToLocal = SPACE(16)
>    SystemTimeToTzSpecificLocalTime(lcTz, lcSystem, @lcSystemToLocal)
>SET STEP ON
>    extract_time(lcSystemToLocal, @lnYearL, @lnMonthL, @lnDowL, @lnDayL, @lnHourL, @lnMinL, @lnSecL, @lnMsecL)
>
>
>**********
>* Convert manual system time to local time
>******
>    ltDateTime = CTOT("11/18/2013 06:14:41PM")
>    stuff_time(@lcSystem, ltDateTime)
>    SystemTimeToTzSpecificLocalTime(lcTz, lcSystem, @lcSystemToLocal)
>SET STEP ON
>    extract_time(lcSystemToLocal, @lnYearL, @lnMonthL, @lnDowL, @lnDayL, @lnHourL, @lnMinL, @lnSecL, @lnMsecL)
>    SUSPEND
>
>
>
>
>FUNCTION extract_time
>LPARAMETERS pcTime, pnYear, pnMonth, pnDow, pnDay, pnHour, pnMin, pnSec, pnMsec
>    pnYear      = extract_16_bits(SUBSTR(pcTime, 1, 2))
>    pnMonth     = extract_16_bits(SUBSTR(pcTime, 3, 2))
>    pnDow       = extract_16_bits(SUBSTR(pcTime, 5, 2))
>    pnDay       = extract_16_bits(SUBSTR(pcTime, 7, 2))
>    pnHour      = extract_16_bits(SUBSTR(pcTime, 9, 2))
>    pnMin       = extract_16_bits(SUBSTR(pcTime, 11, 2))
>    pnSec       = extract_16_bits(SUBSTR(pcTime, 13, 2))
>    pnMsec      = extract_16_bits(SUBSTR(pcTime, 15, 2))
>
>
>
>
>FUNCTION stuff_time
>LPARAMETERS pcTime, ptDateTime
>    pcTime      = SPACE(16)
>    pcTime      = STUFF(pcTime,  1, 2, stuff_16_bits(YEAR(ptDateTime)))
>    pcTime      = STUFF(pcTime,  3, 2, stuff_16_bits(MONTH(ptDateTime)))
>    pcTime      = STUFF(pcTime,  5, 2, stuff_16_bits(DOW(ptDateTime)))
>    pcTime      = STUFF(pcTime,  7, 2, stuff_16_bits(DAY(ptDateTime)))
>    pcTime      = STUFF(pcTime,  9, 2, stuff_16_bits(HOUR(ptDateTime)))
>    pcTime      = STUFF(pcTime, 11, 2, stuff_16_bits(MINUTE(ptDateTime)))
>    pcTime      = STUFF(pcTime, 13, 2, stuff_16_bits(SEC(ptDateTime)))
>    pcTime      = STUFF(pcTime, 15, 2, stuff_16_bits(0))
>
>
>
>
>FUNCTION extract_16_bits
>LPARAMETERS pcString
>    * Convert from raw binary into integer
>    RETURN ASC(pcString) + ASC(SUBSTR(pcString, 2)) * 256
>
>
>
>
>FUNCTION stuff_16_bits
>LPARAMETERS pnValue
>    * Convert from raw binary into integer
>    RETURN CHR(BITAND(pnValue, 0xff)) + CHR(BITRSHIFT(pnValue, 8))
>
Tommy Tillman A+ NetWork+ MCP
Previous
Reply
Map
View

Click here to load this message in the networking platform