milliseconds

How to get current time in milliseconds in PHP?

怎甘沉沦 提交于 2019-11-26 18:15:52
time() is in seconds - is there one in milliseconds? The short answer is: $milliseconds = round(microtime(true) * 1000); kennytm Use microtime . This function returns a string separated by a space. The first part is the fractional part of seconds, the second part is the integral part. Pass in true to get as a number: var_dump(microtime()); // string(21) "0.89115400 1283846202" var_dump(microtime(true)); // float(1283846202.89) Beware of precision loss if you use microtime(true) . There is also gettimeofday that returns the microseconds part as an integer. var_dump(gettimeofday()); /* array(4)

How to get milliseconds from LocalDateTime in Java 8

旧巷老猫 提交于 2019-11-26 17:56:15
问题 I am wondering if there is a way to get current milliseconds since 1-1-1970 (epoch) using the new LocalDate , LocalTime or LocalDateTime classes of Java 8. The known way is below: long currentMilliseconds = new Date().getTime(); or long currentMilliseconds = System.currentTimeMillis(); 回答1: I'm not entirely sure what you mean by "current milliseconds" but I'll assume it's the number of milliseconds since the "epoch," namely midnight, January 1, 1970 UTC. If you want to find the number of

Get current time in milliseconds using C++ and Boost

你。 提交于 2019-11-26 17:40:39
问题 In my thread (using boost::thread) I need to retrieve the current time in ms or less and to convert into ms: Actually, reading here I've found this: tick = boost::posix_time::second_clock::local_time(); now = boost::posix_time::second_clock::local_time(); And seems to work, but after I need to have a long value of the milliseconds of the now... How can I do it? 回答1: You can use boost::posix_time::time_duration to get the time range. E.g like this boost::posix_time::time_duration diff = tick -

How do you specify the date format used when JAXB marshals xsd:dateTime?

瘦欲@ 提交于 2019-11-26 17:20:48
When JAXB marshals a date object ( XMLGregorianCalendar ) into an xsd:dateTime element how can you specify the format of the resulting XML? For example: The default data format is uses milliseconds <StartDate>2012-08-21T13:21:58.000Z</StartDate> I need to omit the milliseconds. <StartDate>2012-08-21T13:21:58Z</StartDate> How can I specify the output form/date format that I want it to use? I'm using javax.xml.datatype.DatatypeFactory to create the XMLGregorianCalendar object. XMLGregorianCalendar xmlCal = datatypeFactory.newXMLGregorianCalendar(cal); bdoughan You can use an XmlAdapter to

Timestamp with a millisecond precision: How to save them in MySQL

空扰寡人 提交于 2019-11-26 16:07:26
I have to develop a application using MySQL and I have to save values like "1412792828893" which represent a timestamp but with a precision of a millisecond. That is, the amount of milliseconds since 1.1.1970. I declare the row as timestamp but unfortunately this didn't work. All values are set to 0000-00-00 00:00:00 CREATE TABLE IF NOT EXISTS `probability` ( `id` int(11) NOT NULL AUTO_INCREMENT, `segment_id` int(11) NOT NULL, `probability` float NOT NULL, `measured_at` timestamp NOT NULL, `provider_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ; How should be the declaration in order to be able

How to get millisecond and microsecond-resolution timestamps in Python [duplicate]

假如想象 提交于 2019-11-26 14:31:00
问题 This question already has answers here : High-precision clock in Python (13 answers) Closed last year . I finally figured this out and would like to share the knowledge and save someone a bunch of time, so see my answer below. However, I still need answers for Linux, so please answer if you know, as my code in my answer is for Windows only. UPDATE: I've figured it out for Linux too, including for pre-Python 3.3 (ex: for the Raspberry Pi), and I've posted my new module/code in my answer below.

What is the duration of a Toast LENGTH_LONG and LENGTH_SHORT

橙三吉。 提交于 2019-11-26 14:02:29
问题 I need the exact duration of LENGTH_LONG and LENGTH_SHORT in milliseconds (ms). Also I need to know if the duration of Toast message with LENGTH_LONG will have the same duration in any phone and with any API version. Does someone know where is the duration defined ?, I mean defined in ms . I know that LENGTH_LONG is some int const with value 1. But I could not find where is the actual duration defined. 回答1: Answered here. Like you mentioned Toast.LENGTH_SHORT and Toast.LENGTH_LONG are not in

Get DateTime.Now with milliseconds precision

僤鯓⒐⒋嵵緔 提交于 2019-11-26 11:51:02
问题 How can I exactly construct a time stamp of actual time with milliseconds precision? I need something like 16.4.2013 9:48:00:123. Is this possible? I have an application, where I sample values 10 times per second, and I need to show them in a graph. 回答1: How can I exactly construct a time stamp of actual time with milliseconds precision? I suspect you mean millisecond accuracy . DateTime has a lot of precision, but is fairly coarse in terms of accuracy. Generally speaking, you can't. Usually

Java date parsing with microsecond or nanosecond accuracy

安稳与你 提交于 2019-11-26 11:25:00
According to the SimpleDateFormat class documentation , Java does not support time granularity above milliseconds in its date patterns. So, a date string like 2015-05-09 00:10:23.999750900 // The last 9 digits denote nanoseconds when parsed via the pattern yyyy-MM-dd HH:mm:ss.SSSSSSSSS // 9 'S' symbols actually interprets the whole number after the . symbol as (nearly 1 billion!) milliseconds and not as nanoseconds, resulting in the date 2015-05-20 21:52:53 UTC i.e. over 11 days ahead. Surprisingly, using a smaller number of S symbols still results in all 9 digits being parsed (instead of, say

Java - alternative to thread.sleep

房东的猫 提交于 2019-11-26 11:21:15
问题 I have a requirement to pause a while loop for a specific number of milliseconds. I have tried using Thread.sleep(duration) but it is not accurate, especially in a looping scenario. Millisecond accuracy is important in my program. Here is the algorithm where I don\'t want to go back to check for condition until expectedElapsedTime has passed by. while (condition) { time = System.currentTimeMillis(); //do something if (elapsedTime(time) < expectedElapsedTime) ) { pause the loop // NEED