Here you can find the source of formatTime(Date time)
Parameter | Description |
---|---|
time | date to process |
public static String formatTime(Date time)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; import java.util.Calendar; import java.util.Date; import java.util.Formatter; public class Main { private static DecimalFormat twoDecimalFormat = new DecimalFormat("#.##"); /**/*from ww w . ja v a2s . c om*/ * Returns specified date in format "YYYY-MM-DD HH:MM:SS" (YYYY-year, * MM-month, DD-day; HH-hour, MM-minutes, SS-seconds). * * @param time * date to process * @return string representation of date in format above */ public static String formatTime(Date time) { Calendar calendar = Calendar.getInstance(); calendar.setTime(time); Formatter formatter = new Formatter(); formatter.format("%04d-%02d-%02d %02d:%02d:%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)); return formatter.toString(); } public static String format(double number) { return twoDecimalFormat.format(number); } }