java.util.date

Parse svn log -xml date output using SimpleDateFormat

↘锁芯ラ 提交于 2019-12-14 02:15:15
问题 The date format of the xml output of the svn log command is like the following. 2014-04-24T08:51:58.213757Z I tried to parse this to a util.Date object using SimpleDateFormat with the following String. yyyy-MM-ddTHH:mm:ss.SSSSSSZ Complete method protected Date formatDate(String dateString) { //2014-04-24T08:51:58.213757Z DateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss.SSS"); format.setTimeZone(TimeZone.getTimeZone("Asia/Colombo")); Date date = null; int lengthToParse = "yyyy-MM

java.time.LocalDate to java.util.Date

陌路散爱 提交于 2019-12-13 04:08:39
问题 What is the best way to convert from java.time.LocalDate to java.util.Date ? Date.from(dateToReturn.atStartOfDay(ZoneId.systemDefault()).toInstant() I have been trying this one but does not seem to work correct with the time although converts the date month and year correctly. Update : java.time.LocalDate does not save time informations Just used java.time.LocalDateTime instead and everything works fine. 回答1: LocalDate ld = ...; Instant instant = ld.atStartOfDay().atZone(ZoneId.systemDefault(

Creating report in java with JDBC and trying to convert between sql date and java util date

夙愿已清 提交于 2019-12-13 02:34:29
问题 I'm making some reports in java which then get added to a jTable after execution of an sql query. However, I have a date format in my table and I can't work out how to convert between the java sql date and java util date. I've tried a few options but I always get this error: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "DATE" at line 1, column 28. This is what my statement code looks like: public void ordersReport() { // if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) ==

How to retrieve DATETIME format from Sqlite database

限于喜欢 提交于 2019-12-12 07:57:16
问题 I have stored date (java.util.date object) in a DATETIME field of a Sqlite table. Now, how to retrieve this date which would be of the same format as java.util.date. Actually I want to compare the time difference (in milliseconds) between current date and the store date. 回答1: Retrieve as Cursor.getString() and pass that value to SimpleDateFormat to make the date object. There is no straight method for getting the date object. 回答2: Thank you, Gopinath. Here's code that I used to perform what

Calendar.HOUR_OF_DAY confusion

巧了我就是萌 提交于 2019-12-11 11:14:30
问题 I have this piece of code: Calendar cal = Calendar.getInstance(); cal.setTime(pDatum); cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(pHHMMTP.substring(0, 2))); cal.set(Calendar.MINUTE, Integer.valueOf(pHHMMTP.substring(2, 4))); cal.set(Calendar.MILLISECOND, 0); System.out.println(cal.getTime()); where pDatum is Sun Mar 27 00:00:00 CET 2016 , pHHMMTP is 02485 and pHHMMTP.substring(0, 2) is 02 . The output is: Sun Mar 27 03:48:00 CEST 2016 I would expect: Sun Mar 27 02:48:00 CEST 2016 First I

convert date to timestamp UTC

限于喜欢 提交于 2019-12-11 10:49:15
问题 I am new to Java and wanted to know how can I convert date to timestamp like http://www.timestampconvert.com/?go1=true&m=08&d=06&y=2007&hours=05&min=30&sec=000&Submit=++++++Convert+to+timestamp+++++&offset=-5.5 if I pass a date to it and vice versa.. I searched here on StackOverflow but none of the questions have solved my problem I need to use this timestamp in my JSON as a parameter on the highcharts API to show points http://www.highcharts.com/samples/data/jsonp.php?filename=msft-c.json

Unexplained zero added when going from java.util.Date to java.sql.Timestamp

折月煮酒 提交于 2019-12-11 04:59:44
问题 Consider the following test code (Try it here yourself on ideone.com - an online Java compiler): class Main { public static void main (String[] args) throws Exception { Main m = new Main(); m.test1(); System.out.println(); m.test2(); } void test1() throws Exception { System.out.println("TEST 1: "); String strTimestamp = "1957-04-27 00:00:00.01"; System.out.println(strTimestamp + " [Original String]"); String format = "yyyy-MM-dd HH:mm:ss.SS"; System.out.println(format + " [Format used]");

SimpleDateFormat incorrectly parsing string

拟墨画扇 提交于 2019-12-11 03:32:32
问题 String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss.SSSSSS"); Date d = f.parse(s); system.out.println(d); this is the code I am running it runs fine except when it prints it prints the time 19:17:46. Please someone explain this to me As a side note: String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss"); Date d = f.parse(s); system.out.println(d); this code will print the same string correctly minus the milliseconds. Someone please tell me what I am

How to convert java.sql.Date to java.util.Date in dd/MM/yyyy format?

你说的曾经没有我的故事 提交于 2019-12-10 11:56:16
问题 I am storing a date to database by converting util date to sql date by using following code SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setLenient(false); java.sql.Date dobSQLDate = null; Date date = null; if(!("").equals(userDob)){date = sdf.parse(userDob);dobSQLDate = new java.sql.Date(date.getTime());} now I want to show this date on my page in the dd/mm/yyyy format in which it was taken... How do I convert this? 回答1: you can use the format method on your

Whats the difference between java.util.Date and Zoneddatetime?

微笑、不失礼 提交于 2019-12-08 11:06:23
问题 While using util.date and giving date with time to service from browser and then saving to db and taking it back it gives different date time against setting zoneddatetime directly from service. Any help would be appreciated.. 回答1: tl;dr Whats the difference between java.util.Date and Zoneddatetime? Date represents a moment in UTC, while ZonedDateTime represents a moment in a particular time zone. Date is a terrible class, riddled with design flaws, that should never be used, while