Time to covert is 1ms
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class MyDateUtilStuff {
private static DateFormat ISO_8601_DATE_TIME = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ");
static {
ISO_8601_DATE_TIME.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public static void main(String[] args) {
String string = "1305637849064";
long startTime = System.currentTimeMillis();
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Long.parseLong(string));
String outDate = ISO_8601_DATE_TIME.format(date);
long time = System.currentTimeMillis() - startTime;
System.out.println(">>> alexey: MyDateUtilStuff.main ii = " + time);
System.out.println(">>> alexey: MyDateUtilStuff.main outDate = "
+ outDate);
}
}
4 comments:
thanks !
String now = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).toString();
private String getTimeZone() {
TimeZone z = Calendar.getInstance().getTimeZone();
int offset = z.getRawOffset();
if (z.inDaylightTime(new Date())) {
offset = offset + z.getDSTSavings();
}
int offsetHrs = offset / 1000 / 60 / 60;
int offsetMins = offset / 1000 / 60 % 60;
String offsetHrsString = (offsetHrs < 10 ? "0" : "") + offsetHrs;
String offsetMinsString = (offsetMins < 10 ? "0" : "") + offsetMins;
String offsetString = "UTC" + (offset < 0 ? "-" : "+") + offsetHrsString + ":" + offsetMinsString;
return offsetString;
}
/**
* Parse date string: "2013-06-05T12:50:13+0200"
* to date string: "2013-06-05 13:50:13"
*
* @param enddate
* @return
* @throws ParseException
*/
private String parseToCorrectFormat(String enddate) throws ParseException {
DateFormat ISO_8601_DATE_TIME = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
ISO_8601_DATE_TIME.setTimeZone(Calendar.getInstance().getTimeZone());
Date d = ISO_8601_DATE_TIME.parse(enddate);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String actualNow = (simpleDateFormat.format(d)).toString();
return actualNow;
}
Post a Comment