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 getFlushMonth() { Calendar cal = Calendar.getInstance(); String stringDate = new SimpleDateFormat("yyyy-MM").format(cal.getTime()); return stringDate; }
From source file:Main.java
public static String getStrDay() { Calendar now = Calendar.getInstance(); return new SimpleDateFormat("yyyy-MM-dd", Locale.US).format(now.getTime()); }
From source file:Main.java
/** * Determines the Date "date" adjusted by the number of hours passed in. * A Negative int will go back a few hours. This always uses the current * date/ time as opposed to the getDateAdjustedByDays() method below which * uses the passed in Date argument as the base to use. * @param hrs Number of hours to adjust by * @return Returns a date object// w w w. j a va 2 s .c o m */ public static Date getDateAdjustedByHours(int hrs) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR_OF_DAY, hrs); return cal.getTime(); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") static String setDate() { // add DateTime to filename Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date currentLocalTime = cal.getTime(); SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd"); date.setTimeZone(TimeZone.getDefault()); _currentDate = date.format(currentLocalTime); return _currentDate; }
From source file:Main.java
public static Date changeDate(int days) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, days); return calendar.getTime(); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") static String setDateTime() { // add DateTime to filename Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date currentLocalTime = cal.getTime(); SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); date.setTimeZone(TimeZone.getDefault()); _currentDateTime = date.format(currentLocalTime); return _currentDateTime; }
From source file:Main.java
public static String CreateTimeFormat_second(long time) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time);/*from ww w.j a v a 2s. c o m*/ return formatter.format(cal.getTime()); }
From source file:Main.java
public static String getTimeMillisToFullDate(long milliSeconds) { Calendar cal = Calendar.getInstance(); java.util.Date currentTime = cal.getTime(); // Create a DateFormatter object for displaying date in specified format. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // String ndate = formatter.format(currentTime); // Create a calendar object that will convert the date and time value in milliseconds to date. cal.setTimeInMillis(milliSeconds);/*from ww w .j ava 2s . com*/ return formatter.format(cal.getTime()); }
From source file:Main.java
/** * Returns current unix date in GMT as long value * * @return current date as long// w w w. j ava 2s. c om */ public static long getCurrentLongDate() { Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); return cal.getTime().getTime(); }
From source file:Main.java
public static String getTimeMillisToYyyyMmDdDate(long milliSeconds) { Calendar cal = Calendar.getInstance(); java.util.Date currentTime = cal.getTime(); // Create a DateFormatter object for displaying date in specified format. SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); // String ndate = formatter.format(currentTime); // Create a calendar object that will convert the date and time value in milliseconds to date. cal.setTimeInMillis(milliSeconds);/*from w w w . ja v a2 s .c o m*/ return formatter.format(cal.getTime()); }