Here you can find the source of getThisWeek()
Description:Get the start date - end date string before current week according to week number
specified by parameter The format is "yyyy/MM/dd-yyyy/MM/dd"Parameter | Description |
---|
public static String getThisWeek()
//package com.java2s; /*//ww w . j a v a 2 s. c o m * $RCSfile: DatetimeUtil,v $$ * $Revision: 1.0 $ * $Date: 2011 $ * * Copyright (C) 2011 GyTech, Inc. All rights reserved. * * This software is the proprietary information of GyTech, Inc. * Use is subject to license terms. */ import java.text.DateFormatSymbols; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; public class Main { /**array reprsents offset bewwen Monday and current date, start from Sunday*/ private static final int[] offsets = { -6, 0, -1, -2, -3, -4, -5 }; /** * <p>Description:Get the start date - end date string before current week according to week number</p> * specified by parameter * The format is "yyyy/MM/dd-yyyy/MM/dd" * @param int weekNum * @return SortedMap */ public static String getThisWeek() { Calendar now = Calendar.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd", new DateFormatSymbols(Locale.US)); int day = now.get(Calendar.DAY_OF_WEEK); int offset = offsets[day - Calendar.SUNDAY] - 1; now.add(Calendar.DAY_OF_YEAR, offset); String temp = null; now.add(Calendar.DAY_OF_YEAR, +1); temp = formatter.format(now.getTime()); now.add(Calendar.DAY_OF_YEAR, +6); temp += "-" + formatter.format(now.getTime()); return temp; } }