View Full Version : Get the date and time into one integer
Master BAW
06-22-2012, 07:14 PM
Hi,
I need to get the date and time into an integer.
GetSystemTime returns something like 301,521,000.... that's milliseconds and thats only 83 hours... what does this mean exactly?
What I really need is a number that can be converted to the date and time in seconds, i don't need miliseconds.
Actually something like this would be usefull:
http://php.net/manual/en/function.time.php
(but that's PHP :( )
putonajonny
06-22-2012, 07:18 PM
"now" is a double that holds the date and the time, you can decode it using DecodeDate and DecodeTime, that might work for what you want?
Runaway
06-22-2012, 07:18 PM
GetSystemTime is how long you're computer has been running for. I think TheTime and TheDate might be what you're looking for... what are you trying to do with time? You can combine them like this:
var
TheNow: String;
TheNow := TheTime + TheDate(Whatever goes here);
Writeln(TheNow);
EDIT: Forgot the "The" on the value assignment :S
Master BAW
06-22-2012, 07:19 PM
yes I will test it :) but what exactly is a "double"? lol
Master BAW
06-22-2012, 07:22 PM
GetSystemTime is how long you're computer has been running for. I think TheTime and TheDate might be what you're looking for... what are you trying to do with time? You can combine them like this:
var
TheNow: String;
Now := TheTime + TheDate(Whatever goes here);
Writeln(TheNow);
ah okay I understand this now :) thank you both!
Writeln(TimeRunning)
That writes how long the script was running.
Master BAW
06-22-2012, 07:29 PM
Writeln(TimeRunning)
That writes how long the script was running.
yeah I don't need that because I try two scripts to communicate with eachother :) And they need to know how late it is and how long ago a message was sent..;)
EDIT:
Interesting....
program New;
{$i SRL\SRL.simba} // includes all main functions
begin // ------------ main loop ---------- \\
SetupSRL; // essential function to make bots work
writeln(TheTime);
//writeln(TheDate);
writeln(Now);
wait(1000);
writeln(Now);
Now
end.
returns this:
Compiled successfully in 624 ms.
SRL Compiled in 15 msec
09:29:58 PM
41082.8958119907
41082.8958235995
Successfully executed.
so what does the decimals mean? because it isn't in miliseconds as you can see...
Edit: found out that a second is about 0.0000115740695.... because this...
program New;
{$i SRL\SRL.simba} // includes all main functions
var
a,b: extended;
c: integer;
begin
SetupSRL; // essential function to make bots work
for c:= 0 to 60 do
begin
a:= Now;
wait(1000);
b:= Now;
writeln(b-a);
end;
end.
returns this:
SRL Compiled in 16 msec
0.00001157407678
0.0000115740695
0.00001157407678
0.0000115740695
0.00001157407678
0.00001157407678
0.00001157407678
0.0000115740695
0.0000115740695
0.0000115740695
0.00001157407678
0.00001157407678
0.0000115740695
0.00001157407678
0.0000115740695
0.00001158565282
0.00001157407678
0.0000115740695
0.00001157407678
0.00001157407678
0.00001157407678
0.0000115740695
0.00001157407678
0.00001158564555
0.00001157407678
0.0000115740695
0.00001157407678
0.00001157407678
0.00001157407678
0.00001157407678
0.00001157407678
0.0000115740695
0.0000115740695
0.00001158564555
0.0000115740695
0.00001157407678
0.00001158565282
0.00001157407678
0.00001157407678
0.00001157407678
0.00001157407678
0.00001158565282
0.0000115740695
0.00001157407678
0.0000115740695
0.00001157407678
0.00001157407678
0.00001157407678
0.0000115740695
0.00001157407678
0.00001158565282
0.00001157407678
0.0000115740695
0.00001157407678
0.00001157407678
0.00001157407678
0.00001157407678
0.0000115740695
0.0000115740695
0.00001157407678
0.00001157407678
Successfully executed.
uhhh so EXCEL says that the average equals 0.000011575231836333 so a second is 0.000011575231836333....
Now returns 41082.9062785532....
41082.9062785532/0.000011575231836333 = 3549208072 , so many seconds is it.
1 year = 31556926 seconds
3549208072 / 3549208072 = 112.47001919147429495636133244198
ahhhhhh so Now has started counting on 1900 :D
lol
ah I know how it is... 41082.9110943171 is the time from 1 Januari 1900 in DAYS
Runaway
06-22-2012, 07:55 PM
If you're trying to give an entry in a log a timestamp, you can just use GetSystemTime. That way you won't have to deal with all that junk Now is giving you. Since GetSystemTime will always work (at least when you're running both scripts at the same time) it should be effective. I guess it doesn't work if you are trying to do something long-term though...
EDIT: Also, what is the problem with using TheTime? Are you having trouble comparing it to other date + time strings?
Janilabo
06-22-2012, 08:19 PM
You need to use DecodeDate and DecodeTime.
Something like this (just a small example, prints hours:minutes:seconds(:milliseconds), day.month.year):
function Test: string;
var
milliseconds, seconds, minutes, hours, day, month, year: Word;
begin
DecodeDate(Now, year, month, day);
DecodeTime(Now, hours, minutes, seconds, milliseconds);
Result := (ToStr(hours) + ':' + ToStr(minutes) + ':' + ToStr(seconds) + '(:' + ToStr(milliseconds) + '), ' +
ToStr(day) + '.' + ToStr(month) + '.' + ToStr(Year));
end;
begin
WriteLn(Test);
end.
Master BAW
06-22-2012, 09:41 PM
Nah I don't need conversion or anything, I made these two little functions and they'll be 100% allright to me because I only need how many minutes from a timepoint it was. :)
Function Time: integer;
begin
Result := round(86400000*Now);//time/date-point in ms
end;
Function MinutesFromDate(Date: integer) : integer;
begin
Result := floor((Time-Date)/60000);
end;
I tested this and it works :):)
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.