`

java中时间格式化

阅读更多
import java.util.Date;
import java.text.DateFormat;

/**
* 格式化时间类
* DateFormat.FULL = 0
* DateFormat.DEFAULT = 2
* DateFormat.LONG = 1
* DateFormat.MEDIUM = 2
* DateFormat.SHORT = 3
* @author    Cc.liu chun_chun_liu@163.com
* @version   1.0, 2005/04/16
*/

public class FormatDate{
    public static void main(String []args){
        Date d = new Date();
        String s;
         
        /** Date类的格式: Sat Apr 16 13:17:29 CST 2005 */
        System.out.println(d);
         
        System.out.println("******************************************");  
       
        /** getDateInstance() */
        /** 输出格式: 2005-4-16 */
        s = DateFormat.getDateInstance().format(d);
        System.out.println(s);
       
        /** 输出格式: 2005-4-16 */
        s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
        System.out.println(s);
       
        /** 输出格式: 2005年4月16日 星期六 */
        s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
        System.out.println(s);
       
        /** 输出格式: 2005-4-16 */
        s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
        System.out.println(s);
       
        /** 输出格式: 05-4-16 */
        s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
        System.out.println(s);
       
        System.out.println("******************************************");
    }
}    
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics