JAVA基础整理之三——时间处理

1、格式化:
Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);
sdf.format(date)。
2、获取年份、月份等:
Calendar cal = Calendar.getInstance();
    int day = cal.get(Calendar.DATE);
    int month = cal.get(Calendar.MONTH) + 1;
    int year = cal.get(Calendar.YEAR);
    int dow = cal.get(Calendar.DAY_OF_WEEK);
    int dom = cal.get(Calendar.DAY_OF_MONTH);
    int doy = cal.get(Calendar.DAY_OF_YEAR);
3、时间戳转换成时间:
Long timeStamp = System.currentTimeMillis();  
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    String sd = sdf.format(new Date(Long.parseLong(String.valueOf(timeStamp))));

猜你喜欢

转载自blog.csdn.net/hz348618754/article/details/79966067
今日推荐