Here you can find the source of datetostring(Date dateInst)
public static String datetostring(Date dateInst) throws ParseException
//package com.java2s; //License from project: LGPL import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String datetostring(Date dateInst) throws ParseException { //String dateTime = "2002-02-02T22:22:22Z"; //String dateTime = "2002-02-02"; SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); String dtstring = formatter.format(dateInst); return dtstring; }//from w w w. ja va 2 s . c o m }