List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:Main.java
public static Calendar getCalendarWithTime(long time) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); return calendar; }
From source file:Main.java
public static String getTimeFromLong(long l) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(l); Calendar t = Calendar.getInstance(); t.set(Calendar.HOUR_OF_DAY, 0); t.set(Calendar.MINUTE, 1);/*from w ww .j ava 2s . c o m*/ t.set(Calendar.SECOND, 0); if (c.after(t)) { NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumIntegerDigits(2); return nf.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + nf.format(c.get(Calendar.MINUTE)); } else { return TIME_NONE; } }
From source file:Main.java
public static int daysSince(final long date) { final Calendar logDate = Calendar.getInstance(); logDate.setTimeInMillis(date); logDate.set(Calendar.SECOND, 0); logDate.set(Calendar.MINUTE, 0); logDate.set(Calendar.HOUR_OF_DAY, 0); final Calendar today = Calendar.getInstance(); today.set(Calendar.SECOND, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.HOUR_OF_DAY, 0); return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d); }
From source file:Main.java
public static String StampToyyyyMMdd(long stamp) { Date date = null;/*ww w . j a v a2s . c om*/ Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(stamp); date = calendar.getTime(); String format = "yyyy-MM-dd"; SimpleDateFormat sdf = new SimpleDateFormat(format); //sdf.setTimeZone(TimeZone.getTimeZone("UTC")); sdf.setTimeZone(TimeZone.getTimeZone("PRC")); return sdf.format(date); }
From source file:Main.java
/** * Convert a timestamp to a date.// w w w .j a va 2 s . c o m * * @param milliseconds * @return */ public static Date millisecondsToDate(long milliseconds) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(milliseconds); return cal.getTime(); }
From source file:Main.java
public static String parseDate(long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeInMillis); Date date = calendar.getTime(); return formatDate(date); }
From source file:Main.java
/** * Same as the getCurrentDay() method but uses the passed in argument * as a long milliseconds timestamp to calculate vs a day object * @parma timestamp This is the time (in milliseconds from the epoch date) * used to calculate the current day of the year. (IE 365 = Dec 31st) * @return Day Day of the year based on timestamp. *//*w w w . j a v a 2 s . c om*/ public static Integer getCurrentDay(long timestamp) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timestamp); return cal.get(Calendar.DAY_OF_YEAR); }
From source file:Main.java
static public String getTimeAsString(long time, String format) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); return getTimeAsString(c, format); }
From source file:Main.java
public static String parseDateTime(long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeInMillis); Date date = calendar.getTime(); return formatDateTime(date); }
From source file:Main.java
/** * Takes in a duration in minutes and a start timestamp and returns * the formatted time that is timestamp + duration *//*from w w w. j a va 2 s . co m*/ public static String getTimeAfterStart(long startTime, int duration) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(startTime); calendar.add(Calendar.MINUTE, duration); int minute = calendar.get(Calendar.MINUTE); String minuteString = ""; if (minute < 10) minuteString = "0" + minute; else minuteString = "" + minute; String timeString = calendar.get(Calendar.HOUR) + ":" + minuteString + " " + AM_PM[calendar.get(Calendar.AM_PM)]; return timeString; }