I need a function that returns the local time in milliseconds on the CPP target.
I tried Haxe's Date class, but Date.now() gives me the time in seconds.
Sys.time() * 1000.0 - http://api.haxe.org/Sys.html#time
Gives the most precise timestamp value (in seconds)
To be clear, I tried this and got millisecond resolution on the cpp target. Sys is available on cpp, cs, java, macro, neko, php and python.
You could try Date.now().getTime(), however:
Returns the timestamp of the date. It might only have a per-second precision depending on the platforms.
A fast way of getting a timestamp would be to use the haxe.Timer.stamp() method.
Example:
import haxe.Timer;
var timestamp:Float = Timer.stamp(); // return a timestamp in seconds with fractions
Note that the value itself might differ depending on platforms, only differences between two values make sense.
Related
I am using moment().valueOf() to get unix timestamp and to get the normal time from unix time i'm using moment.unix(unix_time).format('LLL') when the unix value is 1606985226404 getting the anser as May 2, 52893 6:36 AM which is incorrect. What is the issue with this?
According to the documentation of Moment.JS, moment() works with milliseconds.
So:
const unix_time = moment().valueOf(); // return epoc in milliseconds
const now = moment.unix(unix_time / 1000).format('LLL').
That's the trick.
Trying to convert time as a string to a time variable.
Use Date/Dates/Convert String to Date...... for format I use %H:%M:%S....
Here is the syntax from the GUI
[Convert String Variables to Date]
BSkystrptime (varNames = c('Time'),dateFormat = "%H:%M:%S",prefixOrSuffix = "prefix",prefixOrSuffixValue = "Con_",data = "Dataset2")
BSkyLoadRefreshDataframe(dframe=Dataset2,load.dataframe=TRUE)
A screen shot of result is attached....
Compare variables Time [string] to Con_Time [date/time]
The hours are 2 hours out [wrong!] - the Minutes and Seconds are correct.
What am I doing wrong here?
Screen Shot
I believe you are running into a known issue with a prior release of BlueSky Statistics. This issue is fixed with the current stable release available on the download page.
The reason for this was although the time is converted correctly into the local time zone, BlueSky Statistics was reading the time zone in the local time zone and converting it to UTC.
You are probably +2 hours ahead of UTC, so you are seeing the time move 2 hrs back. Give us a couple of days to post a patch.
You can also confirm this by writing and executing the following syntax in the syntax window
Dataset2$Con_Time
I am stuck with this problem.
I already got the currentUTCtime in seconds from the QDateTime.
Problem is, I can't find a possible way to convert this into the local time in seconds. There are some QDate functions like toLocalTime() which just don't seem to work. I hope somebody here can help me.
QDateTime::currentMSecsSinceEpoch();
QDateTime currentateTime = QDateTime::currentDateTime();
QDateTime UTC(QDateTime::currentDateTimeUtc());
currentDateTime.toString().toStdString();
TimeNow = currentDateTime.toMSecsSinceEpoch()/1000;
Above is my code for the currentUTC Time in seconds.
If you just need the time in seconds since the epoch you can use QDateTime::toTime_t(); this method exists in Qt 4.7 and seems to be a part of Qt 5 from the start, too.
QDateTime::currentDateTime().toTime_t()
for local time, or for UTC
QDateTime::currentDateTimeUtc().toTime_t()
Use QDateTime::fromTime_t, to which the documentation states:
Returns a datetime whose date and time are the number of seconds that have passed since 1970-01-01T00:00:00, Coordinated Universal Time (Qt::UTC) and converted to the given spec.
qint64 utcTime = QDateTime::currentMSecsSinceEpoch();
QDateTime localTime = QDateTime::fromTime_t(utcTime, Qt::LocalTime);
I'm reading a date in a field, ex: 23/01/2015 11:04:06.265842 I would like to get 23/01/2015 11:04:06.26.
The purpose is to compare two datetime and get the result time, for example 2.16 seconds between the two times.
Actually I'm doing : fields["Date"]=os.date("%c", fields["frame.time_epoch"])
frame.time_epoch come from a .pcap file (wireshark)
EDIT:
You can't get millisecond precision with os.date - the maximum resolution it allows is second (see it here http://www.lua.org/pil/22.1.html)
You could try adding it yourself:
local epoch = fields["frame.time_epoch"]
local milliseconds = (epoch - math.floor(epoch))*1000
fields["Date"]=("%s.%03d"):format(os.date("%c", epoch), milliseconds)
I'm trying to get the current time as TimeStamp without success.
I have this code:
QDateTime setTime = QDateTime::fromString (QString("1970-07-18T14:15:09"), Qt::ISODate);
QDateTime current = QDateTime::currentDateTime();
uint msecs = setTime.time().msecsTo(current.time());
return QString::number(msecs);
The output is
Sunday, January 25th 1970, 03:17:35 (GMT)
In Qt 4.7, there is the QDateTime::currentMSecsSinceEpoch() static function, which does exactly what you need, without any intermediary steps. Hence I'd recommend that for projects using Qt 4.7 or newer.
I think you are looking for this function:
http://doc.qt.io/qt-5/qdatetime.html#toTime_t
uint QDateTime::toTime_t () const
Returns the datetime as the number of seconds that have passed since 1970-01-01T00:00:00, > Coordinated Universal Time (Qt::UTC).
On systems that do not support time zones, this function will behave as if local time were Qt::UTC.
See also setTime_t().
Since Qt 5.8, we now have QDateTime::currentSecsSinceEpoch() to deliver the seconds directly, a.k.a. as real Unix timestamp. So, no need to divide the result by 1000 to get seconds anymore.
Credits: also posted as comment to this answer. However, I think it is easier to find if it is a separate answer.