Here you can find the source of formatUTC(Date time)
Parameter | Description |
---|---|
time | a parameter |
public static final String formatUTC(Date time)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { /**/*from www .jav a 2 s . c o m*/ * Date-Time formater that corresponds to the standard UTC time as used in XML * @param time * @return */ public static final String formatUTC(Date time) { // This function needs optimising. It has a too high object churn. Calendar c = null; if (c == null) c = Calendar.getInstance(); c.setTime(time); return c.get(Calendar.YEAR) + "-" + formatInt2(c.get(Calendar.MONTH) + 1) + "-" + formatInt2(c.get(Calendar.DAY_OF_MONTH)) + "T" + formatInt2(c.get(Calendar.HOUR_OF_DAY)) + ":" + formatInt2(c.get(Calendar.MINUTE)) + ":" + formatInt2(c.get(Calendar.SECOND)) + "Z"; } /** * Formats an integer to 2 digits, as used for example in time. * I.e. a 0 gets printed as 00. **/ public static final String formatInt2(int n) { if (n < 10) { return "0" + n; } else { return Integer.toString(n); } } }