json,jersey,jackson,jax-rs,java.util.date
You just need to configure the SerializationFeature.WRITE_DATES_AS_TIMESTAMPS on the ObjectMapper. From what I tested I didn't need to configure the deserialization, it worked fine passing a timestamp. @Provider public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> { private final ObjectMapper mapper; public ObjectMapperContextResolver() { mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true); } @Override public...
You can first convert the number into a long (if you receive a BigInteger, you can call BigInteger.longValue()). Then you have two options. With the standard java.util.Date you can use: long millis = 1435555326831L; Date d = new Date(millis); You can then format the date with a SimpleDateFormat for output....
java,xml,svn,simpledateformat,java.util.date
You need to quote the T because you want it to match literally. You also want X as the format specifier for the time zone, not Z: yyyy-MM-dd'T'HH:mm:ss.SSSSSSX Or you could specify the time zone as UTC, and quote the Z as well. yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z' However, you may still have problems...
java,mysql,date,jdbc,java.util.date
Use a PreparedStatement. It's almost never correct to use string concatenation to create SQL code to send through JDBC. PreparedStatement ps = connection.prepareStatement("insert into device_sales_details values(?)"); ps.setDate(1, sqlDate); int i = ps.executeUpdate(); More about not using string concatenation here: http://bobby-tables.com Separately, it's generally best to specify the columns when doing...
LocalDate ld = ...; Instant instant = ld.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); Date res = Date.from(instant); Check out this blog post, Converting between Date and java8 java.time.LocalDateTime, LocalDate and LocalTime by joachim....
java,java-ee,timezone,java.util.date
You could do the following: Define the dates you have in String variables like this: String date1 = "Tue Oct 21 17:05:37 EDT 2014"; String date2 = "Wed Oct 22 18:05:37 IST 2014"; String date3 = "Thu Oct 23 19:05:37 EST 2014"; Create the representation of the current format that...
new SimpleDateFormat("dd-MM-yyyy:HH:mm:ss.sss") You're never printing milliseconds here. Read the javadoc of SimpleDateFormat, or the answers you already got. The pattern for milliseconds is SSS, not sss. sss prints seconds. Note that even in your incorrect test, you got 10 values being printed. And that is a proof that the 10...
java,android,parsing,java.util.date
This looks like the standard ISO-8601 date format. Try: yyyy-MM-dd'T'HH:mm:ssZ This is very close to the first format you tried, with the addition of "Z". That character is for the UTC offset....
java,date-format,simpledateformat,java.util.date
If I understand your question, then yes. Using the pattern letters given in the documentation for SimpleDateFormat and something like public static void main(String[] args) { String fmtString = "EEEE MMM d, yyyy 'at' h:mm a"; // E - Day name in week // M - Month in year //...
java,cassandra,deprecated,datastax,java.util.date
Could you try like tihs; // create a calendar Calendar cal = Calendar.getInstance(); cal.setTime(datetime); //use java.util.Date object as arguement // get the value of all the calendar date fields. System.out.println("Calendar's Year: " + cal.get(Calendar.YEAR)); System.out.println("Calendar's Month: " + cal.get(Calendar.MONTH)); System.out.println("Calendar's Day: " + cal.get(Calendar.DATE)); As mentioned in javadocs; @Deprecated public...
Short answer: // From Date to YearMonth YearMonth yearMonth = YearMonth.from(date.toInstant() .atZone(ZoneId.systemDefault()) .toLocalDate()); // From YearMonth to Date // The same as the OP:s answer final Date convertedFromYearMonth = Date.from(yearMonth.atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant()); Explanation: The JavaDoc of the YearMonth.from(TemporalAccessor)-method says: The conversion extracts the YEAR and MONTH_OF_YEAR fields. The extraction is only permitted...
android,android-timepicker,java.util.date
I don't think you're going to have to use the Date object for this. Here's a simple example. Let's say you have a button which on clicking presents you the TimePickerDialog. The onClick() event of the Button would look something like this @Override public void onClick(View v) { // Process...
java,object,casting,java.util.date
You are missing a cast. Additionally, you'd be better off using the instanceof operator: for(Object[] myobject : mydata){ // Note that java.sql.Date extends java.util.Date if (myobject[1] instanceof java.util.Date) { java.util.Date mydate = (java.util.Date) myobject[1]; } } ...