Sign in to follow this  
Followers 0
AlmarM

JavaScript "new Date().getTime();" function

10 posts in this topic

#1 ·  Posted (edited)

It calculates the difference between today and 01/01/1970 in ms.

_DateDiff:

  • D = Difference in days between the given dates
  • M = Difference in months between the given dates
  • Y = Difference in years between the given dates
  • w = Difference in Weeks between the given dates
  • h = Difference in hours between the given dates
  • n = Difference in minutes between the given dates
  • s = Difference in seconds between the given dates
Does anyone have a solution for me? I tried editing _DateDiff, but failed. ;)

EDIT: Execute this Javascript code to get the current result:

javascript:alert(new Date().getTime());

If you don't know how to execute it, enter this code inside your browsers URL bar and hit Enter.

Reference: http://www.w3schools.com/jsref/jsref_getTime.asp

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



Thanks Almar !

Javascript should be more present in our forum ! Posted Image

For get it in the same window you can try like this :

javascript:t=new Date().getTime()


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Thanks Almar !

Javascript should be more present in our forum ! Posted Image

Well, i'm making a HTML5 and Javascript game on my work. I noticed the function, and wanted to test something with it inside AutoIt.

It's a Mobile Game ;)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Well, i'm making a HTML5 and Javascript game on my work. I noticed the function, and wanted to test something with it inside AutoIt.

It's a Mobile Game ;)

If you want incorporate javascript command in AutoIt you can try this :

#include <IE.au3>

ConsoleWrite ( "Time : " & _GetTime ( ) & @Crlf )

Func _GetTime ( )
    $_JScriptCmd = 'javascript:t=new Date().getTime() '
    $oIE = ObjCreate ( "InternetExplorer.Application" ) 
    $oIE.Visible = 0 ; 1
    $oIE.Left = 0   
    $oIE.Top = 0      
    $oIE.Width = @DesktopWidth /3
    $oIE.Height = @DesktopHeight /3
    $oIE.Menubar = 0 
    $oIE.Toolbar = 0
    $oIE.Statusbar = 0
    $oIE.Resizable = 0      
    $oIE.Navigate ( '' )
    $oIE.Navigate ( $_JScriptCmd ) 
    $_Text = _IEBodyReadText ( $oIE ) 
    _IEQuit ( $oIE )
    Return $_Text
EndFunc
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

If you want incorporate javascript command in AutoIt you can try this :

#include <IE.au3>

ConsoleWrite ( "Time : " & _GetTime ( ) & @Crlf )

Func _GetTime ( )
    $_JScriptCmd = 'javascript:t=new Date().getTime() '
    $oIE = ObjCreate ( "InternetExplorer.Application" ) 
    $oIE.Visible = 0 ; 1
    $oIE.Left = 0   
    $oIE.Top = 0      
    $oIE.Width = @DesktopWidth /3
    $oIE.Height = @DesktopHeight /3
    $oIE.Menubar = 0 
    $oIE.Toolbar = 0
    $oIE.Statusbar = 0
    $oIE.Resizable = 0      
    $oIE.Navigate ( '' )
    Sleep ( 500 )
    $oIE.Navigate ( $_JScriptCmd ) 
    $_Text = _IEBodyReadText ( $oIE ) 
    _IEQuit ( $oIE )
    Return $_Text
EndFunc

I think that's a bit to expensive.

In my Javascript the getTime() is used to calculate a time Delta (used for Update function). This is calculated each frame.

I think I can't create this object each frame. ;)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

The example in the help file is wrong for you ?

#include <Date.au3>

; Calculated the number of seconds since EPOCH (1970/01/01 00:00:00) 
$iDateCalc = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc())
MsgBox( 4096, "", "Number of seconds since : " & $iDateCalc )

It return date diff in second ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

The example in the help file is wrong for you ?

#include <Date.au3>

; Calculated the number of seconds since EPOCH (1970/01/01 00:00:00) 
$iDateCalc = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc())
MsgBox( 4096, "", "Number of seconds since : " & $iDateCalc )

It return date diff in second ! Posted Image

I need ms ;)

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Now that's a bugger!

Ahh, well... nothing then.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

1 second = 1000 milli seconds

Thus:

#include <Date.au3>

; Calculated the number of seconds since EPOCH (1970/01/01 00:00:00)
$iDateCalc = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc())
MsgBox( 4096, "", "Number of milli seconds since : " & $iDateCalc * 1000 )

Br,

UEZ:blink:


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
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
Sign in to follow this  
Followers 0