Jump to content

what does Timerinit() timestamp represent?


Recommended Posts

K i just ran into a problem today, I assumed the timestamp was just a millisecond representation of the time for today. But I just double checked and the number is a hell of alot bigger then it should be. What exactly does it represent, the time from a certain time on a certain day to now in milliseconds?

Link to comment
Share on other sites

Hm... interesting, but if we devide it by 1000 to get seconds, there is 4 digits that are changing constantly...

So, this is how we can compute the boot time:

$sBootTime = _GetLastBootTime(":")

ConsoleWrite($sBootTime)

Func _GetLastBootTime($sDelim=":")
    Local $iSeconds = StringTrimRight(Round(TimerInit() / 1000), 4)
    Local $iHours, $iMins, $iSecs
    
    If Number($iSeconds) >= 0 Then
        $iHours = Int($iSeconds / 3600)
        $iSeconds = Mod($iSeconds, 3600)
        $iMins = Int($iSeconds / 60)
        $iSecs = Round(Mod($iSeconds, 60))
        
        If StringLen($iHours) = 1 Then $iHours = "0" & $iHours
        If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
        If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
        
        Return $iHours & $sDelim & $iMins & $sDelim & $iSecs
    EndIf
    
    Return SetError(1, 0, 0)
EndFunc

?

:)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hm... interesting, but if we devide it by 1000 to get seconds, there is 4 digits that are changing constantly...

So, this is how we can compute the boot time:

$sBootTime = _GetLastBootTime(":")

ConsoleWrite($sBootTime)

Func _GetLastBootTime($sDelim=":")
    Local $iSeconds = StringTrimRight(Round(TimerInit() / 1000), 4)
    Local $iHours, $iMins, $iSecs
    
    If Number($iSeconds) >= 0 Then
        $iHours = Int($iSeconds / 3600)
        $iSeconds = Mod($iSeconds, 3600)
        $iMins = Int($iSeconds / 60)
        $iSecs = Round(Mod($iSeconds, 60))
        
        If StringLen($iHours) = 1 Then $iHours = "0" & $iHours
        If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
        If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
        
        Return $iHours & $sDelim & $iMins & $sDelim & $iSecs
    EndIf
    
    Return SetError(1, 0, 0)
EndFunc

?

:)

Ok so definately something way off base here as my comp was rebooted less then 48 hours ago and this is giving me a 4 digit number for hours.
Link to comment
Share on other sites

This matches the uptime correctly for me (From Everest).

$milliseconds = TimerDiff(0)
$years = Int($milliseconds / 31536000000)
$remainMS = Mod($milliseconds, 31536000000)
$days = Int($remainMS / 86400000)
$remainMS = Mod($milliseconds, 86400000)
$hours = Int($remainMS / 3600000)
$remainMS = Mod($milliseconds, 3600000)
$minutes = Int($remainMS / 60000)
$remainMS = Mod($milliseconds, 60000)
$seconds = Int($remainMS / 1000)
$remainMS = Mod($milliseconds, 1000)

MsgBox(0,"Time since last boot","Years: " & $years & @CRLF & "Days: " & $days & @CRLF & "Hours: " & $hours & @CRLF & "Minutes: " & $minutes & @CRLF & "Seconds: " & $seconds & @CRLF & "Milliseconds: " & Int($remainMS))

#464257

Link to comment
Share on other sites

Ok so here is a small bit of code I was trying out to help me see what the timestamps do:

Global $sec1 = @SEC
Global $timer1 = TimerInit()
Sleep(5000)
Global $sec2 = @SEC
Global $timer2 = TimerInit()
Global $timerdiff1 = TimerDiff($timer1)
Global $timerdiff2 = TimerDiff($timer2)
MsgBox(0, "vars", "sec2 - sec1: " & ($sec2 - $sec1) & " timer2 - timer1: " & ($timer2 - $timer1) & " timerdiff1 - timerdiff2: " & ($timerdiff1 - $timerdiff2) )

I don't get why the heck timer2 - timer1 doesn't result in 5000.xxxx If it is in milliseconds since the last boot then it should be returning 5000 miliseconds give or take a few milliseconds I'm so darned confused here, please help.

Link to comment
Share on other sites

Ok so here is a small bit of code I was trying out to help me see what the timestamps do:

Global $sec1 = @SEC
Global $timer1 = TimerInit()
Sleep(5000)
Global $sec2 = @SEC
Global $timer2 = TimerInit()
Global $timerdiff1 = TimerDiff($timer1)
Global $timerdiff2 = TimerDiff($timer2)
MsgBox(0, "vars", "sec2 - sec1: " & ($sec2 - $sec1) & " timer2 - timer1: " & ($timer2 - $timer1) & " timerdiff1 - timerdiff2: " & ($timerdiff1 - $timerdiff2) )

I don't get why the heck timer2 - timer1 doesn't result in 5000.xxxx If it is in milliseconds since the last boot then it should be returning 5000 miliseconds give or take a few milliseconds I'm so darned confused here, please help.

TimerInit returns the ticks since last boot I think, not mS

TimerDiff takes tics as a parameter and returns mS

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

TimerInit returns the ticks since last boot I think, not mS

TimerDiff takes tics as a parameter and returns mS

So where it says "Returns a timestamp number (in milliseconds)" in the help file is wrong? Is there a way I can switch it from ticks into milliseconds then? I'm looking at ticks to time, would that work for me? I could just convert the hours, mins seconds into milliseconds right?

Link to comment
Share on other sites

So where it says "Returns a timestamp number (in milliseconds)" in the help file is wrong? Is there a way I can switch it from ticks into milliseconds then? I'm looking at ticks to time, would that work for me? I could just convert the hours, mins seconds into milliseconds right?

What the timerdiff function does is takes a timestamp and calculates the time elapsed from there. You can get the start timestamp by timerinit(), like this:

$startTime = TimerInit()
Sleep(5000)
$timeElapsed = TimerDiff($startTime)
MsgBox(0, "Elapsed", $timeElapsed)

It returns a little over 5000 miliseconds (because of time taken to run the timerinit and timerdiff)

Regards,Josh

Link to comment
Share on other sites

What the timerdiff function does is takes a timestamp and calculates the time elapsed from there. You can get the start timestamp by timerinit(), like this:

$startTime = TimerInit()
Sleep(5000)
$timeElapsed = TimerDiff($startTime)
MsgBox(0, "Elapsed", $timeElapsed)

It returns a little over 5000 miliseconds (because of time taken to run the timerinit and timerdiff)

Yeah I know, I had that in my code above. What I'm trying to do is better understand what timerinit returns and how to convert that into milliseconds or something. Specifically I want to be able to take multiple timestamps and compare between them. The helpfile says that timerinit returns a timestamp in milliseconds, but as my testing seems to show, it does not. As martin was saying it returns the ticks since boot time and not the milliseconds. Now what I'm trying to figure out is what the heck ticks are and how to convert that to milliseconds.
Link to comment
Share on other sites

So where it says "Returns a timestamp number (in milliseconds)" in the help file is wrong? Is there a way I can switch it from ticks into milliseconds then? I'm looking at ticks to time, would that work for me? I could just convert the hours, mins seconds into milliseconds right?

Use _TicksToTime() to convert ticks to "real" time
Link to comment
Share on other sites

Ticks = Milliseconds...

Look in the Date.au3 in your AutoIt includes folder for TicksToTime, it also treats them as milliseconds.

Ok well if it is in milliseconds then why if it do a timerinit() wait 5 seconds then do another timerinit() and subtract the results I do not get 5000 as a result? In fact I seem to get an 11 digit number approx 1.3x10^10 As my result is not as I would expect given that timerinit returns milliseconds since boot time, I have to assume that either I did something wrong or timerinit does not return a value in milliseconds. So I provided the code I was using to test it for you convenience so you could help me.

Maybe my computer is just returning a different result than everyone elses? When I run that snippit of code I get something like:

sec2 - sec1: 5 timer2 - timer1: 12999786760 timerdiff1 - timerdiff2: 5002.20332307219

So the first result is as I expect it as is the third, but the second result has me baffled as I would expect it to be approx 5000

So please tell me if I'm making an incorrect leap in logic here or something.

Link to comment
Share on other sites

  • Moderators

Ok well if it is in milliseconds then why if it do a timerinit() wait 5 seconds then do another timerinit() and subtract the results I do not get 5000 as a result? In fact I seem to get an 11 digit number approx 1.3x10^10 As my result is not as I would expect given that timerinit returns milliseconds since boot time, I have to assume that either I did something wrong or timerinit does not return a value in milliseconds. So I provided the code I was using to test it for you convenience so you could help me.

Maybe my computer is just returning a different result than everyone elses? When I run that snippit of code I get something like:

sec2 - sec1: 5 timer2 - timer1: 12999786760 timerdiff1 - timerdiff2: 5002.20332307219

So the first result is as I expect it as is the third, but the second result has me baffled as I would expect it to be approx 5000

So please tell me if I'm making an incorrect leap in logic here or something.

If I understand your question, it's pretty straight forward to me:
Global $nInit, $nDiff1, $nDiff2, $nDiff_1_2
$nInit = TimerInit()
Sleep(5000)
$nDiff1 = TimerDiff($nInit) / 1000
Sleep(5000)
$nDiff2 = TimerDiff($nInit) / 1000
$nDiff_1_2 = $nDiff2 - $nDiff1 ;Remember, ndiff2 is going to be greater than ndiff1

ConsoleWrite("Seconds 1: " & $nDiff1 & @CRLF)
ConsoleWrite("Seconds 2: " & $nDiff2 & @CRLF)
ConsoleWrite("Seconds Diff from 1 and 2: " & $nDiff_1_2 & @CRLF)
Sleep is not "Exact", so the differences I recorded in the console matched fine.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

TimerInit() probably doesn't return a milliseconds format. If it did, these would be equal:

ConsoleWrite(TimerInit() & @CRLF & TimerDiff(0))
That's exactly what I'm trying to say. I've been told it returns ticks and I've been told that ticks = milliseconds I don't know what the heck ticks are, or even if the timestamp is in ticks. What I really want to know is how to turn the timestamps into milliseconds or seconds even. I want to be able to manipulate the timestamps do math on them and all that, but to do that I need them in some variant of seconds (seconds or milliseconds)

I'm thinking of totally giving up on timerinit() and useing _datediff('s', x, y)

The help file is pretty useless in this case, it says it returns a timestamp in milliseconds which it does not. There is 2 things that I want to do:

1) be able figure out the ammount of time between 2 timestamps

2) be able to add or subtract time from a timestamp

So i take a timestamp and if 10 mins passes then i do something But if I pause the script using my custom tray pause another timer is started and when its unpaused i run timerdiff() to see how long it was paused for then I want to add that time to the original timestamp so that the time its paused for doesn't count towards the 10 mins There are some other things I want to do but this is the biggest problem I'm running into. Since I don't know the units of the timestamp, I can't manipulate it. I thought it was in milliseconds, but it didn't work as it was supposed to.

Link to comment
Share on other sites

TimerInit() probably doesn't return a milliseconds format. If it did, these would be equal:

ConsoleWrite(TimerInit() & @CRLF & TimerDiff(0))
Yes and that is what the OP has been saying all the time as as I have understood it.

@Smoke_N

The point is that if TimerInit() returns a time related to mS since the last boot then the difference between the returns from two TimerInit() calls should be equal to the time between the calls in mS. It isn't. So when the Help says that TimerInit() returns a timestamp in mS what does it mean by a time stamp? On two PC's I've tried I get about 3500 times the number of mS (approx).

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...