Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static int getWeekOfYear(String time) { return getWeekOfYear(string2Date(time, DEFAULT_PATTERN)); } public static int getWeekOfYear(String time, String pattern) { return getWeekOfYear(string2Date(time, pattern)); } public static int getWeekOfYear(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.WEEK_OF_YEAR); } public static int getWeekOfYear(long millis) { return getWeekOfYear(millis2Date(millis)); } public static Date string2Date(String time) { return string2Date(time, DEFAULT_PATTERN); } public static Date string2Date(String time, String pattern) { return new Date(string2Millis(time, pattern)); } public static Date millis2Date(long millis) { return new Date(millis); } public static long string2Millis(String time) { return string2Millis(time, DEFAULT_PATTERN); } public static long string2Millis(String time, String pattern) { try { return new SimpleDateFormat(pattern, Locale.getDefault()).parse(time).getTime(); } catch (ParseException e) { e.printStackTrace(); } return -1; } }