Android : date format in a String Android : date format in a String android android

Android : date format in a String


here is a simple way to convert Date to String :

SimpleDateFormat simpleDate = new SimpleDateFormat("dd/MM/yyyy");

String strDt = simpleDate.format(dt);


 Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime();    String timestamp = simpleDateFormat.format(now);

These might come in handy

SimpleDateFormat simpleDateFormat =    new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZZZZ");

this format is equal to --> "2016-01-01T09:30:00.000000+01:00"

SimpleDateFormat simpleDateFormat =    new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");

this format is equal to --> "2016-06-01T09:30:00+01:00"


here is the example for date format

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");Date date = new Date();System.out.println("format 1 " + sdf.format(date));sdf.applyPattern("E MMM dd yyyy");System.out.println("format 2 " + sdf.format(date));