Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Local time and System time
Message
 
À
17/12/1999 17:01:13
Alex Zhadanov
Computer Generated Solutions
New York City, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00305457
Message ID:
00305547
Vues:
16
Alex,

I whipped the following up. Just call UTC_Time with the current date time to retrieve the UTC time.
* FUNCTION: UTC_Time.prg
* Author: George Tasker
* Date: December 17, 1999 - 6:41 PM
* Purpose: Converts a Date/Time value to
* Universal Coordinated Time

LPARAMETER tDateTime

LOCAL ltresult, loConvert, lcsystime,;
  lcfiletime
SET PROCEDURE TO Con_Time ADDITIVE
loConvert = CREATEOBJECT('ConvertTime')
RELEASE PROCEDURE Con_time
lcfiletime = loConvert.SystemToFileTime(tDateTime)
lcfiletime = loConvert.LocalToFileTime(lcfiletime)
lcsystime = loConvert.FileTimeToSystem(lcfiletime)
ltresult = loConvert.SystemToDateTime(lcsystime)
loConvert = NULL
RETURN ltresult

DEFINE CLASS ConvertTime AS CUSTOM
  * Converts to and from FILETIME to SYSTEMTIME
  * structures

  oInteger = ""

  PROCEDURE Init
  
    SET PROCEDURE TO CON_INT ADDITIVE
    This.oInteger = CREATEOBJECT("ConvertInt")
    RELEASE PROCEDURE CON_INT
    RETURN NOT ISNULL(This.oInteger)
  ENDPROC
  
  FUNCTION FileToLocalTime
    * Converts a FILETIME structure
    * from the system time (UTC) to the 
    * local time
    
    LPARAMETER pcFileTime
    * A FILETIME structure
    
    DECLARE SHORT FileTimeToLocalFileTime IN Win32API;
      STRING @lpFileTime, STRING @lpLocalFileTime
    LOCAL lcresult, lcFileTime
    lcFileTime = pcFileTime
    lcresult = REPLICATE(CHR(0), 8)
    = FileTimeToLocalFileTime(@lcFileTime, @lcresult)
    RETURN lcresult
  ENDFUNC
  
  FUNCTION LocalToFileTime
    * Converts a local FILETIME structure
    * a UTC FILETIME structure
    
    LPARAMETER pcFileTime
    
    DECLARE SHORT LocalFileTimeToFileTime IN Win32API;
      STRING @lpLocalFileTime, STRING @lpFileTime
    LOCAL lcresult, lcfiletime
    lcfiletime = pcFileTime
    lcresult = REPLICATE(CHR(0), 8)
    = LocalFileTimeToFileTime(@lcfiletime, @lcresult)
    RETURN lcresult
  ENDFUNC
  
  FUNCTION SystemToFileTime
  
    LPARAMETER pdtvalue
    * Parameter is of type DATETIME
    DECLARE SHORT SystemTimeToFileTime IN Win32API;
      STRING @lpst,	STRING @lpft
    LOCAL lcsystemtime, lcfiletime
    lcfiletime = REPLICATE(CHR(0), 8)
    lcsystemtime = This.CreateSystemTime(pdtvalue)
    = SystemTimeToFileTime(@lcsystemtime, @lcfiletime)
    RETURN lcfiletime
  ENDFUNC
  
  FUNCTION FileTimeToSystem
    * Converts a FILETIME structure
    * to a SYSTEMTIME structure
    
    LPARAMETER pcFileTime
    
    DECLARE SHORT FileTimeToSystemTime IN Win32API;
      STRING @lpFileTime, STRING @lpSystemTime
    LOCAL lcfiletime, lcresult
    lcfiletime = pcFileTime
    lcresult = REPLICATE(CHR(0), 16)
    = FileTimeToSystemTime(@lcfiletime, @lcresult)
    RETURN lcresult
  ENDFUNC
  
  FUNCTION CreateSystemTime
  
    LPARAMETER pdtvalue
    * Parameter is of type DATETIME
    
    LOCAL lcresult, lnyear, lnmonth,;
    lndow, lnday, lnhour, lnminute, lnsec,;
    lnsize
    lnsize = 2
    lnyear = YEAR(pdtvalue)
    lnmonth = MONTH(pdtvalue)
    lndow = DOW(pdtvalue, 0) - 1
    lnday = DAY(pdtvalue)
    lnhour = HOUR(pdtvalue)
    lnminute = MINUTE(pdtvalue)
    lnsec = SEC(pdtvalue)
    WITH This.oInteger
      lcresult = .IntegerToString(lnyear, lnsize) +;
        .IntegerToString(lnmonth, lnsize) +;
        .IntegerToString(lndow, lnsize) +;
        .IntegerToString(lnday, lnsize) +;
        .IntegerToString(lnhour, lnsize) +;
        .IntegerToString(lnminute, lnsize) +;
        .IntegerToString(lnsec, lnsize) +;
        .IntegerToString(0, lnsize)
    ENDWITH
    RETURN lcresult
  ENDFUNC
  
  FUNCTION SystemToDateTime
  
    LPARAMETER pcsystemtime
    * Parameter is a SYSTEMTIME structure
    
    LOCAL ldtresult, lcyear, lcmonth,;
      lcday, lchour, lcmin, lcsec, lnsize
    lnsize = 2
    WITH This.oInteger
      lcyear = STR(.StringToInteger(LEFT(pcsystemtime, lnsize)))
      lcmonth = STR(.StringToInteger(SUBSTR(pcsystemtime, 3, lnsize)))
      lcday = STR(.StringToInteger(SUBSTR(pcsystemtime, 7, lnsize)))
      lchour = STR(.StringToInteger(SUBSTR(pcsystemtime, 9, lnsize)))
      lcmin = STR(.StringToInteger(SUBSTR(pcsystemtime, 11, lnsize)))
      lcsec = STR(.StringToInteger(SUBSTR(pcsystemtime, 13, lnsize)))
    ENDWITH
    ldtresult = CTOT("^" + lcyear + "/" +;
      lcmonth + "/" + lcday + "," + lchour +;
      ":" + lcmin + ":" + lcsec)
    RETURN ldtresult
  ENDFUNC
  
  FUNCTION ConvertFromFileTime
  
    LPARAMETER pcfiletime
    * A file's FILETIME structure
    * in UTC format
    
    LOCAL lcfiletime, ldtresult, lcsystemtime
    lcfiletime = This.FileToLocalTime(pcfiletime)
    lcsystemtime = This.FileTimeToSystem(lcfiletime)
    ldtresult = This.SystemToDateTime(lcsystemtime)
    RETURN ldtresult
  ENDFUNC
  
  FUNCTION ConvertToFileTime
    * Converts a DATETIME to a UTC FILETIME
    * structure
    
    LPARAMETER pdtDateTime
    
    LOCAL lcsystemtime, lcresult
    lcsystemtime = This.CreateSystemTime(pdtDateTime)
    lcresult = This.SystemToFileTime(lcsystemtime)
    lcresult = This.LocalToFileTime(lcresult)
    RETURN lcresult
  ENDFUNC
  
  PROCEDURE Destroy

    This.oInteger = .NULL.
    RETURN
  ENDPROC

ENDDEFINE

DEFINE CLASS ConvertInt AS CUSTOM

  FUNCTION IntegerToString
    
    LPARAMETER pnInteger, pnbytes
    
    LOCAL lcresult, lnbytes, lnmask,;
      lninteger, lni, lnchar
    lcresult = ""
    IF PCOUNT() = 2
      lnbytes = pnbytes
    ELSE
      * Default to DWORD
      lnbytes = 4
    ENDIF
    lninteger = pnInteger
    lnmask = 255
    FOR lni = 1 TO lnbytes
      lnchar = BITAND(lninteger, lnmask)
      lcresult = lcresult + CHR(lnchar)
      lninteger = BITRSHIFT(lninteger, 8)
    NEXT
    RETURN lcresult
  ENDFUNC
  
  FUNCTION StringToInteger
    
    LPARAMETER pcstring, plsigned
    
    LOCAL lnresult, lnlast, lni, llsigned,;
      lnmsb, lnmax
    lnresult = 0
    lnlast = LEN(pcstring)
    * Return Signed Integer?
    IF PCOUNT() = 2
      llsigned = plsigned
    ELSE
      llsigned = .F.
    ENDIF
    FOR lni = 1 TO lnlast
      lnresult = lnresult + ASC(SUBSTR(pcstring, lni, 1)) * (256 ^ (lni - 1))
    NEXT
    IF llsigned
      lnmsb = (lnlast * 8) - 1
      IF BITTEST(lnresult, lnmsb)
        lnmax = (2 ^ (lnmsb + 1))
        lnresult = lnresult - lnmax
      ENDIF
    ENDIF
    RETURN lnresult
  ENDFUNC
ENDDEFINE
This should get what you want.

Let me know if there are any problems.
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform