Java时间格式转换

来源:互联网 发布:黑龙江网络广播电视 编辑:程序博客网 时间:2024/05/01 11:12
 
把当前时间转换成各种格式,下面给出代码:
 
import java.util.Date;
import java.text.SimpleDateFormat;
 
public class Test {
       public static void main(String[] args) {
             
              Date date = new Date();
              String strDate = "";
             
              SimpleDateFormat format = new SimpleDateFormat();
              format.applyPattern("yyyy-MM-dd HH:mm:ss");
              strDate = format.format(date);
              System.out.println(strDate);
             
              format.applyPattern("yyyy-MM-dd");
              strDate = format.format(date);
              System.out.println(strDate);
             
              format.applyPattern("yyyyMMddHHmmss");
              strDate = format.format(date);
              System.out.println(strDate);
             
              format.applyPattern("yyyy'年'MM'月'dd'日'");
              strDate = format.format(date);
              System.out.println(strDate);
       }
 
}