List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
public static boolean isToday(Date thisDate) { String today = getFormatDateTimeDesc(System.currentTimeMillis()); String thisDateCal = getFormatDateTimeDesc(thisDate.getTime()); if (today.substring(0, 10).endsWith(thisDateCal.substring(0, 10))) { return true; } else {/*from w w w . java2s . com*/ return false; } }
From source file:fm.audiobox.core.utils.ModelUtil.java
/** * Given a string representing an UTC date provided by AudioBox server, * this method returns a unix timestamp (always in UTC). * * @param simpleDateFormat the simple date format * @param audioboxDate the string date provided by audiobox server. * * @return unix timestamp/*from ww w .j a v a2s . c o m*/ * * @throws ParseException the parse exception */ public static long toUnixTime(SimpleDateFormat simpleDateFormat, String audioboxDate) throws ParseException { simpleDateFormat.applyPattern(AUDIOBOX_DATE_FORMAT); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = simpleDateFormat.parse(audioboxDate); return date.getTime(); }
From source file:jp.co.opentone.bsol.framework.core.util.CloneUtil.java
/** * ??.//from ww w . j av a 2 s . com * @param date * @return ?? */ public static Date cloneDate(Date date) { if (date == null) { return null; } return new Date(date.getTime()); }
From source file:Main.java
public static Date transformTime(Date date, TimeZone oldZone, TimeZone newZone) { Date finalDate = null;/*from ww w .j av a2 s . c o m*/ if (date != null) { int timeOffset = oldZone.getOffset(date.getTime()) - newZone.getOffset(date.getTime()); finalDate = new Date(date.getTime() - timeOffset); } return finalDate; }
From source file:net.longfalcon.newsj.util.DateUtil.java
public static String formatNNTPDate(Date date) { return RFC_dateFormatter.print(date.getTime()); }
From source file:Main.java
public static boolean isToday(Date date) { Date currentDate = new Date(); Date firstTimeOfDate = firstTimeOfDate(currentDate); float currentSecond = secondFromMilisecond(firstTimeOfDate.getTime()); float actuallySecond = secondFromMilisecond(date.getTime()); float delta = actuallySecond - currentSecond; if (delta >= 0 && delta < 60 * 60 * 24 * 1) { return true; }//from ww w .ja v a 2 s . c om return false; /* * comment Tan's Code to test Today boolean isToday = false; Date * currentTime = new Date(); Calendar cal = Calendar.getInstance(); * cal.setTime(currentTime); * * Calendar calCurrentView = Calendar.getInstance(); * calCurrentView.setTime(date); * * isToday = (cal.get(Calendar.YEAR) == * calCurrentView.get(Calendar.YEAR)) && (cal.get(Calendar.MONTH) == * calCurrentView .get(Calendar.MONTH)) && * (cal.get(Calendar.DAY_OF_MONTH) == calCurrentView * .get(Calendar.DAY_OF_MONTH)); return isToday; */ }
From source file:Main.java
/** * date into display date//from ww w. j a v a 2 s . c o m * * @serverDateStr server date in string format * @return display time (Like 1 second ago, 2 months ago etc.) * */ public static String convertDateToDisplayFormat(Date serverDate) { // current date Date endDate = new Date(); long different = endDate.getTime() - serverDate.getTime(); long seconds = TimeUnit.MILLISECONDS.toSeconds(different); long minutes = TimeUnit.MILLISECONDS.toMinutes(different); long hrs = TimeUnit.MILLISECONDS.toHours(different); long days = TimeUnit.MILLISECONDS.toDays(different); int months = (int) Math.floor(days / 30); int years = (int) Math.floor(months / 12); if (years != 0) { if (years == 1) { return "1 year ago"; } else { return years + " years ago"; } } else if (months != 0) { if (months == 1) { return "1 month ago"; } else { return months + " months ago"; } } else if (days != 0) { if (days == 1) { return "Yesterday"; } else { return days + " Days ago"; } } else if (hrs != 0) { if (hrs == 1) { return hrs + " hour ago"; } else { return hrs + " hours ago"; } } else if (minutes != 0) { if (minutes == 1) { return minutes + " minute ago"; } else { return minutes + " minutes ago"; } } else { if (seconds == 0) { return "Now"; } else if (seconds == 1) { return "1 sec ago"; } else if (seconds > 0) { return seconds + " seconds ago"; } else { return "Now"; } } }
From source file:fr.ericlab.util.Util.java
static public long getTime() { Date date = new Date(); return date.getTime(); }
From source file:Main.java
public static int compareDateToDays(Date firstDate, Date lastDate) { if (firstDate == null || lastDate == null) { System.out.print("NULL"); }// ww w. j av a 2s .c o m long time1 = firstDate.getTime(); long time2 = lastDate.getTime(); long tmpCal = time2 - time1; long mm = 24 * 60 * 60 * 1000; int days = (int) (tmpCal / mm); return Math.abs(days); }
From source file:Util.java
/** * Sets the time on the same day to 00:00:00.000 * * @param date//from w ww . j a v a2s .co m * @return a new date */ @SuppressWarnings("deprecation") public static Date truncateTime(Date date) { Date newDate = (Date) date.clone(); newDate.setHours(0); newDate.setMinutes(0); newDate.setSeconds(0); newDate.setTime(newDate.getTime() - newDate.getTime() % 1000); //Millisekunden auf 0 return newDate; }