milliseconds

How to convert a string Date to long millseconds

孤者浪人 提交于 2019-11-26 09:49:13
问题 I have a date inside a string, something like \"12-December-2012\". How can I convert this into milliseconds (long)? 回答1: Using SimpleDateFormat String string_date = "12-December-2012"; SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy"); try { Date d = f.parse(string_date); long milliseconds = d.getTime(); } catch (ParseException e) { e.printStackTrace(); } 回答2: SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date date = (Date)formatter.parse("12-December-2012"); long

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

左心房为你撑大大i 提交于 2019-11-26 08:53:52
问题 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.

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

笑着哭i 提交于 2019-11-26 06:01:27
问题 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,

Java date parsing with microsecond or nanosecond accuracy

拜拜、爱过 提交于 2019-11-26 02:25:38
问题 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.