首页 > 其他 > 详细

Date 获取日期 SimpleDateFormat

时间:2016-08-12 10:10:05      阅读:354      评论:0      收藏:0      [点我收藏+]

技术分享

package Baozhuang;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest {
    public static void main(String[] args) {
        //获取当前日期和时间
        Date date = new Date();
        System.out.println("当前时间:"+date);
        
        //对当前日期进行规范    日期类型与字符串转换 SimpleDateFormat
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String time = dateFormat.format(date);
        System.out.println("年-月-日  时:分:秒"+time);
        
        //E月份里的星期几
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("E");
        String week = dateFormat2.format(date);
        System.out.println("今天是:"+week);
        //F月份里的星期 同W
        SimpleDateFormat dateFormat3 = new SimpleDateFormat("F");
        String week2 = dateFormat3.format(date);
        System.out.println("今天是第"+week2+"周");
        
        //W月份中的周数     w年份中的周数
        SimpleDateFormat dateFormat4 = new SimpleDateFormat("W");
        String week3 = dateFormat4.format(date);
        System.out.println("今天是第:"+week3+"周");
        //a  am/pm标记
        SimpleDateFormat dateFormat5 = new SimpleDateFormat("a");
        String day = dateFormat5.format(date);
        System.out.println("上午/下午"+day);
        
    }
}

技术分享

 

Date 获取日期 SimpleDateFormat

原文:http://www.cnblogs.com/xiaolei121/p/5763835.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!