Java examples for java.util:Minute
return a String for now format is (YEAR/MONTH/DAY,HOUR:MINUTE:SECONDS.MILLISECONDS)
//package com.java2s; import java.util.Calendar; public class Main { public static void main(String[] argv) throws Exception { System.out.println(getTimeStringFromNow()); }/*from w w w . j a va 2s. c o m*/ /** * return a String for now * format is (YEAR/MONTH/DAY,HOUR:MINUTE:SECONDS.MILLISECONDS) * @return */ public static String getTimeStringFromNow() { Calendar.getInstance().setTimeInMillis(System.currentTimeMillis()); StringBuilder sb = new StringBuilder(); sb.append("("); sb.append(Calendar.getInstance().get(Calendar.YEAR)); sb.append("/"); sb.append(Calendar.getInstance().get(Calendar.MONTH)); sb.append("/"); sb.append(Calendar.getInstance().get(Calendar.DAY_OF_MONTH)); sb.append(","); sb.append(Calendar.getInstance().get(Calendar.HOUR_OF_DAY)); sb.append(":"); sb.append(Calendar.getInstance().get(Calendar.MINUTE)); sb.append(":"); sb.append(Calendar.getInstance().get(Calendar.SECOND)); sb.append("."); sb.append(Calendar.getInstance().get(Calendar.MILLISECOND)); sb.append(")"); return sb.toString(); } }