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:Main.java
public static boolean isToday(String s1) { boolean ret = false; Calendar tmp = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String s2 = format.format(tmp.getTime()); if (s1.equals(s2)) { ret = true;//w w w . j a va2 s .c o m } return ret; }
From source file:Main.java
/** * Sleeps the current thread until the specified future date. If the date is before the current time, * the thread will resume operation immediately. * // www .java2s. c om * @param date */ public static void sleepUntil(int year, int month, int day, int hour, int min, int sec) { Calendar cal = Calendar.getInstance(); cal.set(year, month, day, hour, min, sec); long msFuture = cal.getTime().getTime(); long msNow = System.currentTimeMillis(); long msSleep = msFuture - msNow; if (msSleep <= 0) { return; } try { Thread.sleep(msFuture - msNow); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static void updateLabel(EditText et, Calendar calendar) { String format = "dd/MM/yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.US); et.setText(sdf.format(calendar.getTime())); }
From source file:com.taobao.tddl.sample.util.DateUtil.java
/** * //*from w w w .j a va2s . c o m*/ * * @param intervals * @param format * @return */ public static String getDiffDate(int intervals, String format) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, intervals); Date intervalDay = cal.getTime(); return formatDate(intervalDay, format); }
From source file:Main.java
public static final String getStringTimeFromLong(final long timeInMillis) { final SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy HH:mm"); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(timeInMillis);/* w w w .j a v a2 s. c om*/ c.setTimeZone(TimeZone.getDefault()); return format.format(c.getTime()); }
From source file:com.fanniemae.ezpie.common.DateUtilities.java
public static String toIsoString(Calendar value) { return (value == null) ? "" : toIsoString(value.getTime()); }
From source file:Main.java
/** * Get the seven days before date//w w w. j ava 2 s .co m * * @return {@link String} */ public static String GetDateSevenDaysBack() { DateFormat formatter = new SimpleDateFormat("dd_MMM_yyyy"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, -7); return formatter.format(calendar.getTime()); }
From source file:Main.java
/** * Determines the Date "date" adjusted by "days". * A negative value will return a date in the past. * @param date The date to be adjusted// w w w.j a v a2 s.c o m * @param days The number of days to adjust by * @return Returns a date object */ public static Date getDateAdjustedByDays(Date date, int days) { Calendar cal = Calendar.getInstance(); if (date != null) cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, days); return cal.getTime(); }
From source file:Main.java
public static String format(Calendar c, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format, Locale.getDefault()); return simpleDateFormat.format(c.getTime()); }
From source file:Main.java
public static String getDate() { Calendar c = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = dateFormat.format(c.getTime()); return currentTime; }