Java: unparseable date exception

What you’re basically doing here is relying on Date#toString() which already has a fixed pattern. To convert a Java Date object into another human readable String pattern, you need SimpleDateFormat#format(). private String modifyDateLayout(String inputDate) throws ParseException{ Date date = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss z”).parse(inputDate); return new SimpleDateFormat(“dd.MM.yyyy HH:mm:ss”).format(date); } By the way, the “unparseable date” exception … Read more

Parsing datetime in Python..?

As @TimPietzcker suggested, the dateutil package is the way to go, it handles the first 3 formats correctly and automatically: >>> from dateutil.parser import parse >>> parse(“Fri Sep 25 18:09:49 -0500 2009”) datetime.datetime(2009, 9, 25, 18, 9, 49, tzinfo=tzoffset(None, -18000)) >>> parse(“2008-06-29T00:42:18.000Z”) datetime.datetime(2008, 6, 29, 0, 42, 18, tzinfo=tzutc()) >>> parse(“2011-07-16T21:46:39Z”) datetime.datetime(2011, 7, 16, 21, … Read more

How to format a Java string with leading zero? [duplicate]

public class LeadingZerosExample { public static void main(String[] args) { int number = 1500; // String format below will add leading zeros (the %0 syntax) // to the number above. // The length of the formatted string will be 7 characters. String formatted = String.format(“%07d”, number); System.out.println(“Number with leading zeros: ” + formatted); } }

tech