繁体   English   中英

如何获得周数。 (我有约会)?

[英]How to get week number. (I have date)?

我目前正在从事一个需要查找给定日期的星期数的项目。

您能为我的问题提供一个代码段吗?

谢谢。

你可以试试这个

Calendar now = Calendar.getInstance();


  now.set(Calendar.YEAR,2013);
  now.set(Calendar.MONTH,04);//0- january ..4-May
  now.set(Calendar.DATE, 04);

System.out.println("Current week of month is : " +
            now.get(Calendar.WEEK_OF_MONTH));

System.out.println("Current week of year is : " +
            now.get(Calendar.WEEK_OF_YEAR));

这样可以解决您的问题:

Calendar cal = Calendar.getInstance();
cal.setTime(date);
int weekOfYear = ca.get(Calendar.WEEK_OF_YEAR);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM