Jump to content

Parsing an odd Date string.


Recommended Posts

all,

i trying to parse an xml from a third party tool that extract an odd file date sting value "1184380538000" that somehow translate to "Saturday, April 12, 2008 15:40:22"

the original JS parsing funciton is:

function DateToString(dateDate)
{
    var strRet;
    if (dateDate.valueOf())
        strRet = dateDate.toDateString() + " " + dateDate.toLocaleTimeString();
    else
        strRet = "";
        
    return strRet;
}

any idea?

thanks in advance

Lior.

Link to comment
Share on other sites

Javascript's basic time unit appears to be milliseconds since 01/01/1970 ("The Computer Epoch"). This gives "2007/07/14 02:35:38":

#Include <Date.au3>

$n = 1184380538000
ConsoleWrite("$n = " & $n & @LF)
$sTime = _DateAdd("s", Int($n / 1000), "1970/01/01 00:00:00")
ConsoleWrite("$sTime = " & $sTime & @LF)

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

If you know a date value equals a particular date and time. Then this function will calculate a date and time from a date value.

This method will only work when the date value is the number of milliseconds from a specific date and time.

#include <Date.au3>

Local $sNewDate
Local $ThenknownDateValue = 1184380538000 + 3600000 ; 3,600,000 milliseconds = 1 hr

DateConvertFromKnownConversion(1184380538000, "2008/04/12 15:40:22", $ThenknownDateValue, $sNewDate)

MsgBox(0, "Conversion", $ThenknownDateValue & " converts to " & $sNewDate)

Func DateConvertFromKnownConversion($IfThisDateValue, $EqualsThisDate, $ThenknownDateValue, ByRef $EqualsUnknownDate)
    Local $CalcTime, $hGui, $idDate
    $CalcTime = _DateAdd("s", Int(($ThenknownDateValue - $IfThisDateValue) / 1000), $EqualsThisDate)

    ;Format date
    $hGui = GUICreate("")
    $idDate = GUICtrlCreateDate($CalcTime, 10, 10)
    GUICtrlSendMsg($idDate, 0x1032, 0, "dddd, MMMM d, yyyy HH:mm:ss"); or "hh:mm tt"
    $EqualsUnknownDate = GUICtrlRead($idDate)
    GUIDelete($hGui)
EndFunc ;==>DateConvertFromKnownConversion
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...