JAVA basic finishing three - time processing

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))));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324489300&siteId=291194637