List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
public static String ymd2Timestamp(String dateString) throws ParseException { String timeStamp = null;//from w w w . j av a 2 s .c om SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); Date d; try { d = sdf.parse(dateString); long l = d.getTime() / 1000; timeStamp = String.valueOf(l); } catch (ParseException e) { e.printStackTrace(); } return timeStamp; }
From source file:Main.java
private static long delayToNextMinute() { Date now = new Date(); long sec = Calendar.getInstance().get(Calendar.SECOND); return now.getTime() - sec * 1000 + 61 * 1000; }
From source file:Main.java
public static String getTime(String user_time, String format) { String re_time = null;/*from ww w . j a va 2 s .c om*/ SimpleDateFormat sdf = new SimpleDateFormat(format); Date d; try { d = sdf.parse(user_time); long l = d.getTime(); String str = String.valueOf(l); re_time = str.substring(0, 10); } catch (ParseException e) { e.printStackTrace(); } return re_time; }
From source file:Main.java
public static long parseTimeToLong(String time) { if (null == time) return System.currentTimeMillis(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); java.util.Date d; try {//from ww w. jav a 2s .c om d = sdf.parse(time); return d.getTime(); } catch (Exception e) { e.printStackTrace(); } return System.currentTimeMillis(); }
From source file:Main.java
public static Date convertLocalToUTC(Date local) { Date now = new Date(System.currentTimeMillis()); Date result = new Date(local.getTime() - TimeZone.getDefault().getOffset(now.getTime())); return result; }
From source file:Main.java
/** * Binds the date or null to the statement on the given index. * * @param statement The statement.// w w w .j ava 2 s.co m * @param index The index where the value will be bound. * @param value The value to bind. */ public static void bindDateOrNull(SQLiteStatement statement, int index, @Nullable Date value) { if (value != null) { statement.bindLong(index, value.getTime()); } else { statement.bindNull(index); } }
From source file:Main.java
public static String getTime(String user_time) { String re_time = null;//from ww w . j a va 2 s.c om SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d; try { d = sdf.parse(user_time); long l = d.getTime(); String str = String.valueOf(l); re_time = str.substring(0, 10); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return re_time; }
From source file:cs544.letmegiveexam.util.ExamDuration.java
public static long get(Date startTimestamp) { java.util.Date date = new java.util.Date(); Date currentTimestamp = new Timestamp(date.getTime()); return (currentTimestamp.getTime() - startTimestamp.getTime()) / (60 * 60); }
From source file:Main.java
public static CharSequence getRelativeTimeSpanString(Context context, Date date) { if (date != null) return DateUtils.getRelativeTimeSpanString(context, date.getTime()); return ""; }
From source file:Main.java
public static long diffOfDate2(Date begin, Date end) { if (begin == null || end == null) return 0; long diff = end.getTime() - begin.getTime(); long diffDays = diff / (24 * 60 * 60 * 1000); return diffDays; }