提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在Java 7中处理周数
import java.text.DateFormat; import java.util.Calendar; import java.util.SimpleTimeZone; /** from * 时代Java **/ public class Main { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); if(calendar.isWeekDateSupported()) { System.out.println("Number of weeks in this year: " + calendar.getWeeksInWeekYear()); System.out.println("Current week number: " + calendar.get(Calendar.WEEK_OF_YEAR)); /** 来 自 nowjava - 时 代 Java **/ } calendar.setWeekDate(2012, 16, 3); System.out.println(DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG).format(calendar.getTime())); calendar.setWeekDate(2022, 1, 1); System.out.println(DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.LONG).format(calendar.getTime())); SimpleTimeZone simpleTimeZone = new SimpleTimeZone( -21600000, "CST", Calendar.MARCH, 1, -Calendar.SUNDAY, 7200000,