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 String nowDateYymm() { Calendar cal = Calendar.getInstance(); java.util.Date currentTime = cal.getTime(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); String ndate = formatter.format(currentTime); return ndate; }
From source file:Main.java
public static String getCurrentDateYyyy_Mm_DdHhmmssDash() { Calendar cal = Calendar.getInstance(); java.util.Date currentTime = cal.getTime(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String ndate = formatter.format(currentTime); return ndate; }
From source file:Main.java
public static String geOnlyCurrentTime() { Calendar cal = Calendar.getInstance(); java.util.Date currentTime = cal.getTime(); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); String ndate = formatter.format(currentTime); return ndate; }
From source file:Main.java
/** * Returns the date/* w w w . j a va2s.c o m*/ * @param timestamp This is the long milliseconds date since epoch * @return Returns a date object */ public static Date getDate(Long timestamp) { if (timestamp == null) return null; Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timestamp); return cal.getTime(); }
From source file:Main.java
private static Date get2MinsAgo() { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MINUTE, -2); return calendar.getTime(); }
From source file:Main.java
/** * converts time to UTC format/*from ww w. ja v a 2 s. co m*/ */ public static String getHourFormatted(Date createdUTC) { Date dateServer = createdUTC; TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date dateGMT = cal.getTime(); return normalDateFormat(dateServer); }
From source file:Main.java
/** * //www .ja v a2 s .co m * @param date * @return */ public static Date getDate(String date) { if ("".equals(date) || date == null || "null".equals(date)) { return null; } else { String[] obj = date.split("-"); int year = Integer.valueOf((String) obj[0]).intValue(); int month = Integer.valueOf((String) obj[1]).intValue(); int day = Integer.valueOf((String) obj[2]).intValue(); Calendar calendar = new GregorianCalendar(year, month - 1, day); return calendar.getTime(); } }
From source file:Main.java
public static String getPreviousDate(int days) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -days); return sdf.format(cal.getTime()); }
From source file:Main.java
public static String now() { Calendar cal = Calendar.getInstance(); return sDefaultDateFormat.format(cal.getTime()); }
From source file:Main.java
public static String msToDate(String ms) { long miliseconds = Long.parseLong(ms); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy hh:mm aaa"); Calendar c = Calendar.getInstance(); c.setTimeInMillis(miliseconds);//from w ww.j a v a 2s . c o m return sdf.format(c.getTime()); }