Here you can find the source of getFormattedTime(final Calendar calendar)
Parameter | Description |
---|---|
calendar | calendar object which holds the current time that needs to be formatted. |
public static String getFormattedTime(final Calendar calendar)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; public class Main { /**/*w ww. j a v a 2 s .c o m*/ * Function to return formatted time * @param calendar * calendar object which holds the current time that needs to be formatted. * @return * the String format of the date and time that the calendar object contained */ public static String getFormattedTime(final Calendar calendar) { SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.format(calendar.getTime()); } /** * Get the standard formatted time string for the given time in milliseconds */ public static String getFormattedTime(long timeInMillis) { return getFormattedTime(getCalendarForTime(timeInMillis)); } /** * Function to return a calendar object holding the UTC representation of the current time. * @param timeInMilliseconds * the time in milliseconds from the Jan 1 1970 epoch that is to be used as the time to set * the calendar to. * @return * the calendar object which represents the time that was passed in in UTC */ public static Calendar getCalendarForTime(final long timeInMilliseconds) { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(timeInMilliseconds); return calendar; } }