参数:String dateStr = '2016-05-18';

1、获取string对应date日期:

Date date = new SimpleDateFormat("yyyy-MM-dd").parse(dateStr );

2、获取date对应的Calendar对象

Calendar ca = Calendar.getInstance();

ca.setTime(date);

3、可以从ca中获取各种该日期的属性值:

int day = ca.get(Calendar.DAY_OF_YEAR);//一年中的第几天

int week = ca.get(Calendar.WEEK_OF_YEAR);//一年中的第几周

int month = ca.get(Calendar.MONTH);//第几个月

int year = ca.get(Calendar.YEAR);//年份数值

备注:之所以要转成Calendar对象,是因为Date的getXXX()方法废弃了。。。

相关文章:

  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-07-17
  • 2021-11-17
  • 2021-10-01
  • 2022-01-25
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-11
相关资源
相似解决方案