Java String to Date object of the format “yyyy-mm-dd HH:mm:ss”

java.util.Date temp = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSSSSS”).parse(“2012-07-10 14:58:00.000000”); The mm is minutes you want MM CODE public class Test { public static void main(String[] args) throws ParseException { java.util.Date temp = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSSSSS”) .parse(“2012-07-10 14:58:00.000000”); System.out.println(temp); } } Prints: Tue Jul 10 14:58:00 EDT 2012

Using GregorianCalendar with SimpleDateFormat

SimpleDateFormat.format() method takes a Date as a parameter. You can get a Date from a Calendar by calling its getTime() method: public static String format(GregorianCalendar calendar) { SimpleDateFormat fmt = new SimpleDateFormat(“dd-MMM-yyyy”); fmt.setCalendar(calendar); String dateFormatted = fmt.format(calendar.getTime()); return dateFormatted; } Also note that the months start at 0, so you probably meant: int month = … Read more

How does Java “week year” really work?

It’s simple: December 27 2015 is day 1 of week 1 of week-year 2016 (and December 27 2026 is day 1 of week 1 of week-year 2027). This can be verified by adding these lines: SimpleDateFormat odf = new SimpleDateFormat(“YYYY-ww-u”); System.out.println(odf.format(d1)); System.out.println(odf.format(d2)); System.out.println(odf.format(d3)); If a SimpleDateFormat outputs a date it can use all fields: year, … Read more

Java date parsing with microsecond or nanosecond accuracy

tl;dr LocalDateTime.parse( // With resolution of nanoseconds, represent the idea of a date and time somewhere, unspecified. Does *not* represent a moment, is *not* a point on the timeline. To determine an actual moment, place this date+time into context of a time zone (apply a `ZoneId` to get a `ZonedDateTime`). “2015-05-09 00:10:23.999750900” // A `String` … Read more

Java Convert GMT/UTC to Local time doesn’t work as expected

I also recommend using Joda as mentioned before. Solving your problem using standard Java Date objects only can be done as follows: // **** YOUR CODE **** BEGIN **** long ts = System.currentTimeMillis(); Date localTime = new Date(ts); String format = “yyyy/MM/dd HH:mm:ss”; SimpleDateFormat sdf = new SimpleDateFormat(format); // Convert Local Time to UTC (Works … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)