List of usage examples for java.util Calendar getTime
public final Date getTime()
Date
object representing this Calendar
's time value (millisecond offset from the Epoch"). From source file:org.zalando.stups.oauth2.spring.client.StupsTokensAccessTokenProviderTest.java
public static Date tomorrow() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, 1); return cal.getTime(); }
From source file:Main.java
/** * Determines what year a transaction belongs to. * /*from ww w . java 2 s .c o m*/ * If the given <code>day</code> of the given <code>month</code> for the current year * is in the future the transaction is probably from last year. * * @param month The month, where January is 1. * @param day The day of the month, starting from 1. * @return An ISO 8601 formatted date. */ public static String getTransactionDate(int month, int day) { month--; // Java-months start at 0 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal = Calendar.getInstance(); int currentYear = cal.get(Calendar.YEAR); cal.set(currentYear, month, day, 0, 0); if (cal.getTime().after(Calendar.getInstance().getTime())) { //If the transaction is in the future the year is probably of by +1. cal.add(Calendar.YEAR, -1); } return sdf.format(cal.getTime()); }
From source file:org.zalando.stups.oauth2.spring.client.StupsTokensAccessTokenProviderTest.java
public static Date yesterday() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, -1); return cal.getTime(); }
From source file:IntDate.java
public static Date getDate(String year, String month, String day) { // Date(int, int, int) has been deprecated, so use Calendar to // set the year, month, and day. Calendar c = Calendar.getInstance(); // Convert each argument to int. c.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); return c.getTime(); }
From source file:Main.java
public static boolean isPast(Date date) { boolean isPast = false; Date currentTime = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(currentTime);/*from ww w . j a v a 2s . c om*/ Calendar calCurrentView = Calendar.getInstance(); calCurrentView.setTime(date); isPast = cal.getTime().after(calCurrentView.getTime()); return isPast; }
From source file:Main.java
public static Date startOfThisWeek() { Calendar cal = Calendar.getInstance(); int firstDay = cal.getFirstDayOfWeek(); cal.set(Calendar.DAY_OF_WEEK, firstDay); return startOfDay(cal.getTime()); }
From source file:Main.java
/** * Convert given calendar to formated string * @param calendar to convert/*from w ww . j a v a 2 s . c o m*/ * @return formated date in string */ @SuppressLint("SimpleDateFormat") public static String calendarToString(Calendar calendar) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setCalendar(calendar); return dateFormat.format(calendar.getTime()); }
From source file:Main.java
/** * Converts the calendar into a string formated according to the xs:date * format.//from ww w .j a v a 2 s .co m * * @param calendar the calendar to convert, must not be null * * @return the new format yyyy-MM-dd */ public static String xsDateFormat(final Calendar calendar) { final SimpleDateFormat dateFormat; dateFormat = new SimpleDateFormat("yyyy-MM-dd"); return dateFormat.format(calendar.getTime()); }
From source file:Main.java
public static String getYestoryDate() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -1); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String yestoday = sdf.format(calendar.getTime()); return yestoday; }
From source file:Main.java
public static Date getFirstDayOfMonth(Date date) { if (date == null) { return null; }/*from www . ja v a 2 s .c om*/ Calendar calendar = Calendar.getInstance(Locale.getDefault()); calendar.setTime(date); calendar.set(Calendar.DAY_OF_MONTH, 1); return calendar.getTime(); }