List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
public static String getUTCTimeFromLocal(String localTime) { java.util.Date UTCDate = null; String localTimeStr = null;/*from w w w . j ava 2 s . c o m*/ SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); try { UTCDate = format.parse(localTime); localTimeStr = format.format(UTCDate.getTime() - TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return localTimeStr; }
From source file:com.leanengine.JsonEncode.java
private static JSONObject getDateNode(Date date) throws JSONException { JSONObject dateNode = new JSONObject(); dateNode.put("type", "date"); dateNode.put("value", date.getTime()); return dateNode; }
From source file:eu.atos.sla.monitoring.simple.TNovaMetricsRetriever.java
private static Long DateToUnixtime(Date time) { //DateFormat dfm = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy"); long unixtime = 0; unixtime = time.getTime(); unixtime = unixtime / 1000;/*from w ww .j ava 2s . c o m*/ return unixtime; }
From source file:com.davis.ddf.crs.utils.CheckUtil.java
public static boolean checkDateInRange(Date from, Date to, CRSEndpointResponse item) { boolean result = false; Long itemDate = item.getDateOccurred().getTime(); if (itemDate > from.getTime() && itemDate < to.getTime()) { result = true;//from w ww .ja v a 2 s .com } return result; }
From source file:Main.java
public static long DateDifference(String dateStart, String dateStop) { //String dateStart = "01/14/2012 09:29:58"; //String dateStop = "01/15/2012 10:31:48"; //HH converts hour in 24 hours format (0-23), day calculation SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = null; Date d2 = null;// w ww .j ava 2s . c o m long diffDays = -1; try { d1 = format.parse(dateStart); d2 = format.parse(dateStop); //in milliseconds long diff = d1.getTime() - d2.getTime(); long diffSeconds = diff / 1000 % 60; long diffMinutes = diff / (60 * 1000) % 60; long diffHours = diff / (60 * 60 * 1000) % 24; diffDays = diff / (24 * 60 * 60 * 1000); /* Log.v("days",diffDays + " days, "); Log.v("Hours",diffHours + " hours, "); Log.v("Minutes",diffMinutes + " minutes, "); Log.v("Seconds",diffSeconds + " seconds.");*/ } catch (Exception e) { e.printStackTrace(); diffDays = -1; } return diffDays; }
From source file:Main.java
public static String getLocalDateTimeFromUTCDateTime(String UTCDateTime) { java.util.Date nowDate = null; String UTCDate = null;// w w w .ja v a 2s . co m SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); try { nowDate = format.parse(UTCDateTime); UTCDate = format.format(nowDate.getTime() + TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return UTCDate; }
From source file:de.arago.rike.commons.util.ViewHelper.java
public static int getDayDifference(Date date) { return (int) Math.ceil((date.getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)); }
From source file:Main.java
public static String getUTCDateTimeFromLocalDateTime(String localTimeStr) { java.util.Date nowDate = null; String UTCDate = null;/*www .j av a 2s . co m*/ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); try { nowDate = format.parse(localTimeStr); UTCDate = format.format(nowDate.getTime() - TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return UTCDate; }
From source file:dataflow.feed.api.Weather.java
/** * Method which connects to the weather API and retrieves the weather from the day before today *//*from w w w. j a v a2 s .c o m*/ public static void getWeather() { String key = "c6aee37b80d801b44279ac16374db"; Calendar fromTime = Calendar.getInstance(); Date weatherDate = new Date(); for (int i = 1; i < 7; i++) { weatherDate.setTime(weatherDate.getTime() - (86400000)); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String date = format.format(weatherDate); String jsonString = callURL( "https://api.worldweatheronline.com/free/v2/past-weather.ashx?q=Rotterdam&format=json&tp=24&key=c6aee37b80d801b44279ac16374db&date=" + date); try { MySQLDb db = new MySQLDb(); JSONObject jsonObject = new JSONObject(jsonString).getJSONObject("data"); db.insertWeather(date, jsonObject); } catch (JSONException e) { throw e; } try { Thread.sleep(250); } catch (InterruptedException ex) { Logger.getLogger(Weather.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.kk.dic.action.Upload.java
private static java.sql.Date getCurrentDate() { java.util.Date today = new java.util.Date(); return new java.sql.Date(today.getTime()); }