Open top menu





   Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String,         and parsing turns a String into a Date.

Show Example:
       Calendar mDate = Calendar.getInstance();
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-dd-mm HH:mm:ss");
       String date=sdf.Format(mDate.getTime());
       Log.i(date,"your date in string");

 

            you have  to get Indian time Zone

                  Date date=new Date();
                  date=setTimeZone(date, Local.getdefault());
                  DateTime datetime= new DateTime(date, TimeZone.getTimeZone("UTC 05:30"));
           

Try more format

      String[] formats = new String[] {
  " yyyy-MM-dd",
   "yyyy-MM-dd HH:mm",
   "yyyy-MM-dd HH:mmZ",
   "yyyy-MM-dd HH:mm:ss.SSSZ",
   "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
 };
 for (String format : formats) {
   SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US);
   System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
   sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
   System.out.format("%30s %s\n", format, sdf.format(new Date(0)));
 }


Tagged

0 comments