Java SimpleDateFormat pattern for W3C XML dates with timezone [duplicate]
If you use Java 7+, this pattern should work (X is for the ISO 8601 time zone): SimpleDateFormat fmt = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ssX”);
If you use Java 7+, this pattern should work (X is for the ISO 8601 time zone): SimpleDateFormat fmt = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ssX”);
You seem to be mixing the patterns for z and Z. If you ignore the (FLE Daylight Time), since this is the same info as in GMT+0300, the problem becomes that SimpleDateFormat wants either GMT +0300 or GMT+03:00. The last variant can be parsed like this: String time = “Sun Jul 15 2012 12:22:00 GMT+03:00 … Read more
As for documentation https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html uppercase D stands for the day number in a year, if you want day number in a month you should use lowercase d. The same for YYYY and yyyy: Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 1996; 96 Y Week year Year 2009; … Read more
This works: public static void main(String[] args) throws Exception { String s = “01:19 PM”; Date time = null; DateFormat parseFormat = new SimpleDateFormat(“hh:mm a”, Locale.ENGLISH); System.out.println(time = parseFormat.parse(s)); } ouputs: Thu Jan 01 13:19:00 KST 1970
I don’t say it’s a nice solution, but it seems to be a way through. Map<Long, String> dayOfWeekTexts = Map.of(1L, “Mo”, 2L, “Di”, 3L, “Mi”, 4L, “Do”, 5L, “Fr”, 6L, “Sa”, 7L, “So”); Map<Long, String> monthTexts = Map.ofEntries(Map.entry(1L, “Jan”), Map.entry(2L, “Feb”), Map.entry(3L, “Mär”), Map.entry(4L, “Apr”), Map.entry(5L, “Mai”), Map.entry(6L, “Jun”), Map.entry(7L, “Jul”), Map.entry(8L, “Aug”), Map.entry(9L, “Sep”), … Read more
The issue for you is that you are using mm. You should use MM. MM is for month and mm is for minutes. Try with yyyy-MM-dd HH:mm Other approach: It can be as simple as this (other option is to use joda-time) static final long ONE_MINUTE_IN_MILLIS=60000;//millisecs Calendar date = Calendar.getInstance(); long t= date.getTimeInMillis(); Date afterAddingTenMins=new … Read more
This should display ‘Tue’: new SimpleDateFormat(“EEE”).format(new Date()); This should display ‘Tuesday’: new SimpleDateFormat(“EEEE”).format(new Date()); This should display ‘T’: new SimpleDateFormat(“EEEEE”).format(new Date()); So your specific example would be: new SimpleDateFormat(“yyyy-MM-EEE”).format(new Date());
I know this has been inactive for a while but hopefully it can be useful to someone. The key here is implement IDateEvaluator interface which is intended to validate if a date is special or invalid. Unfortunately there’s only one concrete implementation provided with JCalendar library which is MinMaxDateEvaluatorclass, but taking this as start point … Read more
I’m sure that if you don’t use that static instance of SimpleDateFormat you will have no problem: public static String getCurrentDateTime() { SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); Date d = new Date(); String datetime = sdf.format(d); return datetime; } See these links: Why is Java’s SimpleDateFormat not thread-safe? “Java DateFormat is not threadsafe” what … Read more
Use: SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”); Use MM for month, mm for minutes as stated by documentation… If you want to print a Date in a specific format, you should use: sdf.format(birthday) or another SimpleDateFormat if you want to pring it in a different format…