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 getWeekIndex(String time) { return getWeekIndex(string2Date(time, DEFAULT_PATTERN)); } public static int getWeekIndex(String time, String pattern) { return getWeekIndex(string2Date(time, pattern)); } public static int getWeekIndex(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.DAY_OF_WEEK); } public static int getWeekIndex(long millis) { return getWeekIndex(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; } }