package test.remote.tools.combine;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TestOutDate {
public static void main(String[] args) { Calendar nowtime =
new GregorianCalendar(); String strDateTime=
"["+String.format(
"d", nowtime.get(Calendar.YEAR))+
"/"+ String.format(
"d", nowtime.get(Calendar.MONTH))+
"/" + String.format(
"d", nowtime.get(Calendar.DATE))+
" " + String.format(
"d", nowtime.get(Calendar.HOUR))+
":" + String.format(
"d", nowtime.get(Calendar.MINUTE))+
":" + String.format(
"d", nowtime.get(Calendar.SECOND))+
"." + String.format(
"d", nowtime.get(Calendar.MILLISECOND))+
"]"; System.out.println(strDateTime); String msg=
""; Date date =
new Date(); SimpleDateFormat sdf =
new SimpleDateFormat(
"YYYY/MM/dd HH:mm:ss.SSS"); msg+=
"["+sdf.format(date)+
"]"; System.out.println(msg); } }
package test.remote.tools.combine;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TestOutDate
{
public static void main(String[] args)
{
//method 1
Calendar nowtime = new GregorianCalendar();
String strDateTime="["+String.format("d", nowtime.get(Calendar.YEAR))+"/"+
String.format("d", nowtime.get(Calendar.MONTH))+"/" +
String.format("d", nowtime.get(Calendar.DATE))+" " +
String.format("d", nowtime.get(Calendar.HOUR))+":" +
String.format("d", nowtime.get(Calendar.MINUTE))+":" +
String.format("d", nowtime.get(Calendar.SECOND))+"." +
String.format("d", nowtime.get(Calendar.MILLISECOND))+"]";
System.out.println(strDateTime);
//method 2
String msg="";
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss.SSS");
msg+="["+sdf.format(date)+"]";
System.out.println(msg);
}
}
运行结果: [2013/08/09 05:54:32.578] [2013/09/09 17:54:32.625]