List of usage examples for java.util Date getTime
public long getTime()
From source file:DateParser.java
public static void test(String isodate) { System.out.println("----------------------------------"); Date date = parse(isodate); System.out.println(">> " + isodate); System.out.println(">> " + date.toString() + " [" + date.getTime() + "]"); System.out.println(">> " + getIsoDate(date)); System.out.println("----------------------------------"); }
From source file:com.amazonaws.util.DateUtils.java
/** * Formats the specified date as an ISO 8601 string. * * @param date//from ww w .ja v a2 s . c o m * The date to format. * * @return The ISO 8601 string representing the specified date. */ public static String formatISO8601Date(Date date) { try { return iso8601DateFormat.print(date.getTime()); } catch (RuntimeException ex) { throw handleException(ex); } }
From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java
/** * 0// w w w. j av a 2 s .c o m * @param d1 ? * @param d2 ? * @return */ @SuppressWarnings("deprecation") public static int getDay1(Date d1, Date d2) { if (d1 == null) return 1; d1.setHours(0); d1.setMinutes(0); d1.setSeconds(0); d2.setHours(0); d2.setMinutes(0); d2.setSeconds(0); long date1 = d1.getTime() / (1000l * 60 * 60 * 24); long date2 = d2.getTime() / (1000l * 60 * 60 * 24); return Long.valueOf(date2 - date1).intValue(); }
From source file:com.whatlookingfor.common.utils.DateUtils.java
public static long pastHour(Date before, Date after) { if (after == null) { after = new Date(); }//from w w w . ja v a2 s.c o m long milliseconds = after.getTime() - before.getTime(); return milliseconds / (1000 * 60 * 60); }
From source file:com.whatlookingfor.common.utils.DateUtils.java
public static long pastMinutes(Date before, Date after) { if (after == null) { after = new Date(); }/*w ww. j a v a 2s .c om*/ long milliseconds = after.getTime() - before.getTime(); return milliseconds / (1000 * 60); }
From source file:com.whatlookingfor.common.utils.DateUtils.java
/** * ?//from ww w .j a v a2 s . c o m * * @return */ public static long pastDays(Date before, Date after) { if (after == null) { after = new Date(); } long milliseconds = after.getTime() - before.getTime(); return milliseconds / (1000 * 60 * 60 * 24); }
From source file:ca.osmcanada.osvuploadr.Utils.Helper.java
public static long getFileTime(File f) { try {/*from w ww . ja v a2 s .c o m*/ Metadata metadata = ImageMetadataReader.readMetadata(f); ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class); Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL); return date.getTime(); } catch (Exception ex) { } return 0; }
From source file:com.dianxin.imessage.common.util.DateUtil.java
/** * ??String//from w w w. j av a 2 s . co m * * @param dateStr * @return */ public static int calculateNumberOfDays(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_FORMAT); try { Date date = sdf.parse(dateStr); Date now = new Date(); long n1 = now.getTime(); long n2 = date.getTime(); if (n1 > n2) { long diffTime = n1 - n2; int numberOfDays = (int) (diffTime / (3600 * 1000 * 24)); return numberOfDays; } else { return 0; } } catch (ParseException e) { return 0; } }
From source file:com.dianxin.imessage.common.util.DateUtil.java
/** * ?// www . j a va 2 s . co m * * @param dateStr * @return */ public static int calculateNumberOfDaysToToday(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_FORMAT); try { Date date = sdf.parse(dateStr); Date now = new Date(); long n1 = now.getTime(); long n2 = date.getTime(); if (n2 >= n1) { long diffTime = n2 - n1; int numberOfDays = (int) (diffTime / (3600 * 1000 * 24)); return numberOfDays; } else { return -1; } } catch (ParseException e) { return -1; } }
From source file:au.com.addstar.SpigotUpdater.java
private static UpdateCallback getUpdateCallBack(SpigetUpdater updater, Plugin p, boolean check) { return new UpdateCallback() { @Override/*from w w w. j a va 2s. c o m*/ public void updateAvailable(ResourceInfo latestResource, String url, boolean hasDirectDownload) { String name = StringUtils.rightPad(p.getName(), 25, " "); Console.Color resouceColor = null; if (latestResource.premium) { resouceColor = Console.Color.ANSI_YELLOW; } List<String> out = new ArrayList<>(); out.add(Console.wrap(name, resouceColor)); out.add(StringUtils.rightPad(p.getResourceID().toString(), 7)); out.add(StringUtils.rightPad(p.getVersion(), 10)); out.add(StringUtils.truncate(StringUtils.rightPad(latestResource.latestVersion.name, 10), 10)); if ((hasDirectDownload || externalDownloads) && !check) { String result; Console.Color color; if (updater.downloadUpdate(p)) { result = "DONE"; color = Console.Color.ANSI_GREEN; } else { result = "FAIL"; color = Console.Color.ANSI_RED; } out.add(Console.wrap(StringUtils.rightPad(result, 7), color)); out.add(StringUtils.rightPad(format.format(p.getLastUpdated()), 10)); if (result.equals("FAIL")) out.add(" REASON: " + updater.getFailReason() + " - URL: " + url); } else { out.add(Console.wrapPad("NO", Console.Color.ANSI_RED, 7)); Console.Color dateColor = null; Date lastUpdate = p.getLastUpdated(); long diff = new Date().getTime() - lastUpdate.getTime(); if (diff > 0) { diff = diff / (60 * 60 * 1000); dateColor = Console.Color.ANSI_BLACK_RED; if (diff < 24) dateColor = Console.Color.ANSI_GREEN; if (diff < 72) dateColor = Console.Color.ANSI_YELLOW; if (diff < 144) dateColor = Console.Color.ANSI_RED; } out.add(Console.wrapPad(format.format(p.getLastUpdated()), dateColor, 10)); out.add(" URL: " + url); } StringBuilder sb = new StringBuilder(); String[] message = new String[out.size()]; out.toArray(message); sb.append(StringUtils.join(message, " | " + Console.Color.ANSI_RESET)); System.out.println(sb.toString()); } @Override public void upToDate() { String name = StringUtils.rightPad(p.getName(), 25, " "); List<String> out = new ArrayList<>(); out.add(name); out.add(StringUtils.rightPad(p.getResourceID().toString(), 7)); out.add(StringUtils.rightPad(p.getVersion(), 10)); out.add(StringUtils.rightPad(p.getVersion(), 10)); out.add(Console.wrap(StringUtils.rightPad("YES", 7), Console.Color.ANSI_GREEN)); out.add(StringUtils.rightPad(format.format(p.getLastUpdated()), 10)); StringBuilder sb = new StringBuilder(); String[] message = new String[out.size()]; out.toArray(message); sb.append(StringUtils.join(message, " | ")); System.out.println(sb.toString()); } }; }