List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
public static long getToday() { Calendar cal = Calendar.getInstance(); String curDate = dateFormater2.get().format(cal.getTime()); curDate = curDate.replace("-", ""); return Long.parseLong(curDate); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static String getFormatedDate(String rawDate, Boolean flag) { Calendar currenttime = Calendar.getInstance(); Calendar commentTime = Calendar.getInstance(); long nextDateInMillis = currenttime.getTimeInMillis(); long commentTimeInMillis = Long.parseLong(rawDate) * 1000; commentTime.setTimeInMillis(commentTimeInMillis); long timeDifferenceMilliseconds = nextDateInMillis - commentTimeInMillis; long diffSeconds = timeDifferenceMilliseconds / 1000; long diffMinutes = timeDifferenceMilliseconds / (60 * 1000); long diffHours = timeDifferenceMilliseconds / (60 * 60 * 1000); long diffDays = timeDifferenceMilliseconds / (60 * 60 * 1000 * 24); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd"); if (flag) {/*from w ww . j a va 2 s. c o m*/ if (diffSeconds < 1) { return "less than a second"; } else if (diffMinutes < 1) { return diffSeconds + "s"; } else if (diffHours < 1) { return diffMinutes + "m"; } else if (diffDays < 1) { return diffHours + "h"; } else if (diffDays < 7) { return diffDays + "d"; } else { return sdf.format(commentTime.getTime()); } } else { if (diffSeconds < 1) { return "Posted Just Now"; } else if (diffMinutes < 1) { if (diffSeconds == 1) return "Posted " + diffSeconds + " Second ago"; else return "Posted " + diffSeconds + " Seconds ago"; } else if (diffHours < 1) { if (diffMinutes == 1) return "Posted " + diffMinutes + " Month ago"; else return "Posted " + diffMinutes + " Months ago"; } else if (diffDays < 1) { if (diffHours == 1) return "Posted " + diffHours + " hour ago"; else return "Posted " + diffHours + " hours ago"; } else if (diffDays < 7) { if (diffDays == 1) return "Posted " + diffDays + " day ago"; else return "Posted " + diffDays + " days ago"; } else { return "Posted on " + sdf.format(commentTime.getTime()); } } }
From source file:Main.java
public static String getLeftDay(String date) { if ("".equals(date) || date == null) { return ""; }/* w ww . j a v a2 s .c o m*/ Date cur = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", getLocale()); String curTime = sdf.format(cur); Date dt = new Date(); long day = 0; try { dt = sdf.parse(curTime); long l = Long.parseLong(date) - dt.getTime(); if (l > 0) { day = l / (24 * 60 * 60 * 1000); } else { day = 0; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } return Long.toString(day); }
From source file:Main.java
public static ArrayList<Long> generateNumbers(String phoneNo) { Log.i("Generating Phone Numbers, from input " + phoneNo, ""); int maxLength = 10; int len = phoneNo.length(); int missing = maxLength - len; String phoneNoStart = phoneNo; String phoneNoEnd = phoneNo;//from w w w .j a v a2 s . c om for (int i = 0; i < missing; i++) { phoneNoStart = phoneNoStart + "0"; phoneNoEnd = phoneNoEnd + "9"; } long phoneStart = Long.parseLong(phoneNoStart); long phoneEnd = Long.parseLong(phoneNoEnd); ArrayList<Long> phoneNoList = new ArrayList<Long>(); for (long j = phoneStart; j <= phoneEnd; j++) { phoneNoList.add(j); } return phoneNoList; }
From source file:Main.java
/** Helper method - gets a named element's value as a <I>long</I>. @param pElement The parent <I>Element</I>. @param strName Name of the element./* w ww .j av a 2 s .c om*/ @return Value of the element. */ public static long getElementLong(Element pElement, String strName) throws ClassCastException, NumberFormatException { String strValue = getElementString(pElement, strName); if (null == strValue) return Long.MIN_VALUE; return Long.parseLong(strValue); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static String getFormatedDate(String rawDate, Boolean flag) { Calendar currenttime = Calendar.getInstance(); Calendar commentTime = Calendar.getInstance(); long nextDateInMillis = currenttime.getTimeInMillis(); long commentTimeInMillis = Long.parseLong(rawDate) * 1000; commentTime.setTimeInMillis(commentTimeInMillis); long timeDifferenceMilliseconds = nextDateInMillis - commentTimeInMillis; long diffSeconds = timeDifferenceMilliseconds / 1000; long diffMinutes = timeDifferenceMilliseconds / (60 * 1000); long diffHours = timeDifferenceMilliseconds / (60 * 60 * 1000); long diffDays = timeDifferenceMilliseconds / (60 * 60 * 1000 * 24); // long diffWeeks = timeDifferenceMilliseconds / (60 * 60 * 1000 * 24 * // 7);// ww w. j a va2 s .co m // long diffMonths = (long) (timeDifferenceMilliseconds / (60 * 60 * // 1000 * 24 * 30.41666666)); // long diffYears = (long) (timeDifferenceMilliseconds / (60 * 60 * 1000 // * 24 * 365)); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd"); if (flag) { if (diffSeconds < 1) { return "less than a second"; } else if (diffMinutes < 1) { return diffSeconds + "s"; } else if (diffHours < 1) { return diffMinutes + "m"; } else if (diffDays < 1) { return diffHours + "h"; } else if (diffDays < 7) { return diffDays + "d"; } else { return sdf.format(commentTime.getTime()); } } else { if (diffSeconds < 1) { return "Posted Just Now"; } else if (diffMinutes < 1) { if (diffSeconds == 1) return diffSeconds + " second ago"; else return diffSeconds + " seconds ago"; } else if (diffHours < 1) { if (diffMinutes == 1) return diffMinutes + " minute ago"; else return diffMinutes + " minutes ago"; } else if (diffDays < 1) { if (diffHours == 1) return diffHours + " hour ago"; else return diffHours + " hours ago"; } else if (diffDays < 7) { if (diffDays == 1) return diffDays + " day ago"; else return diffDays + " days ago"; } else { return sdf.format(commentTime.getTime()); } } }
From source file:Main.java
/** * For a given string that should contain an long value, return either the * <code>long</code> value or a zero if empty. * /* ww w . j a va2 s . c om*/ * @param irodsValue * @return <code>long</code> equivilent of irods value */ public static long getLongOrZeroFromIRODSValue(final String irodsValue) { long result = 0L; if (irodsValue == null) { throw new IllegalArgumentException("null irodsValue"); } if (irodsValue.isEmpty()) { // nothing } else { try { result = Long.parseLong(irodsValue); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("cannot format number:" + irodsValue, nfe); } } return result; }
From source file:Main.java
private static Date parseDate(String d) throws IllegalArgumentException { if (!d.startsWith("@")) throw new IllegalArgumentException(); return new Date(Long.parseLong(d.substring(1))); }
From source file:Main.java
public static void writeSharedPreferences(Context context, String prefsName, String name, Object value) { if (name == null || value == null) { return;/*from w w w .j av a2 s . c o m*/ } SharedPreferences user = context.getSharedPreferences(prefsName, 0); Editor editor = user.edit(); if (value instanceof Integer) { editor.putInt(name, Integer.parseInt(value.toString())); } else if (value instanceof Long) { editor.putLong(name, Long.parseLong(value.toString())); } else if (value instanceof Boolean) { editor.putBoolean(name, Boolean.parseBoolean(value.toString())); } else if (value instanceof String) { editor.putString(name, value.toString()); } else if (value instanceof Float) { editor.putFloat(name, Float.parseFloat(value.toString())); } editor.commit(); }
From source file:Main.java
public static long toLong(String obj) { try {/*from w w w . j a v a 2 s . co m*/ return Long.parseLong(obj); } catch (Exception e) { } return 0; }