java--常用类Date

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  实类的子类;

   }

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值