Date 类
Date d = new Date();
//Date d1 = new Date(1988,11,12); 不推荐使用的方法,已经过时,不能使用
System.out.println(d);//Fri Apr 12 18:22:39 CST 2013
System.out.println(System.currentTimeMillis());//获得当前时间的毫秒数1365762159244
String pattern = "yyyy-MM-dd hh:mm";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String resultDate = sdf.format(d); //2013-04-12 06:22
System.out.println(resultDate);
//---------------------------------------------------
Date d = new Date();
String pattern = "yyyy-MM-dd kk:mm";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String resultDate = sdf.format(d); //2013-04-12 18:22
System.out.println(resultDate);
//--------------------要想显示2013-04-12 18:22 PM-------------------------------
String pattern = "yyyy-MM-dd hh:mm a";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String resultDate = sdf.format(d); //2013-04-12 18:22
<pre name="code" class="java">System.out.println(resultDate); //2013-04-12 18:22 下午 因为 SimpleDateFormat 用给定模式和默认的语言环境的日期格式符号构造
//--------------------要想显示2013-04-12 18:22 PM-------------------------------
Locale locale = new Locale("en","US"); //Locale locale = Locale.ENGLISH;也可以
SimpleDateFormat sdf = new SimpleDateFormat(pattern,locale);
<pre name="code" class="java">String resultDate = sdf.format(d); //2013-04-12 06:22 PM
System.out.println(resultDate);
//--------------------要想显示2013-04-12 18:22 PM-------另一种方式-----------------------
Date d1 = new Date(System.currentTimeMillis());
System.out.println(DataConvertor.formatDate(d1));
Public class DateConvertor{ //指定格式转换
public static String dataToString(Date d,String pattern){
SimpleDateFormat sdf= new SimpleDateFormat(pattern,locale.ENGLISH);
Stirng resultDate=sdf.format(d);
return resultDate;
}
}
int money = 100;
System.out.println("$"+money+".00");//$100.00
//--------------------要想显示1,000,312类似的形式------------------------------
DecimalFormat df = new DecimalFormat("#,##,###,####");
System.out.println(df.format(100000999);
抽象类的初始化
类名 对象 = 类名.getInstance();
public class 类名{
public static 实类 getInstance(){
return 实类的子类;
}
}