List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
/** * Remove index and '-' from layer name. * //from ww w. j a va2s . c o m * @param name * @return */ public static String removeIndex(String name) { int last = name.lastIndexOf("-"); if (name.length() == (last + 1)) { // ends with - not indexed return name; } String indx = name.substring(last + 1); try { // try to parse string after "-" as integer Long.parseLong(indx); // ok, remove index return name.substring(0, last); } catch (Exception ex) { // not valid, not index return name; } }
From source file:Main.java
public static String timestampToDate(String timestamp) { Long unixtimestamp = Long.parseLong(timestamp); // Log.d("Debug", "TimeStamp: " + unixtimestamp); if ("4294967295".equals(unixtimestamp)) { return ""; }/*from ww w.j av a 2 s .c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm"); Date date = new Date(unixtimestamp * 1000); return new SimpleDateFormat("dd/MM/yyyy - HH:mm").format(date); }
From source file:Main.java
public static Long parseLong(String value) { if (value == null) { return 0L; }//from w ww .ja v a2s .c o m Long val = 0L; try { Matcher matcher = pattern.matcher(value); if (matcher.find()) { String num = matcher.group(0); val = Long.parseLong(num); } } catch (Exception e) { e.printStackTrace(); } return val; }
From source file:Main.java
@Deprecated private static Long[] getIdArray(String serializedTree) { ArrayList<Long> ids = new ArrayList<>(); String[] digitsOnly = serializedTree.split("[\\[\\],\\s]"); // Split on [ ] , or whitespace chars for (String idString : digitsOnly) { try {/* ww w.j a v a 2 s . c o m*/ if (!TextUtils.isEmpty(idString)) { ids.add(Long.parseLong(idString)); } } catch (NumberFormatException e) { Log.e("widget-subtasks", "error parsing id " + idString, e); } } return ids.toArray(new Long[ids.size()]); }
From source file:Main.java
public static long parseLong(String value, long defaultValue) { try {/*from w w w .j ava 2 s .c o m*/ return Long.parseLong(value); } catch (NumberFormatException nfe) { return defaultValue; } }
From source file:Main.java
public static int getStudyDay(Context context) { String startStr = getSP(context, SP_LOGIN).getString(SP_KEY_LOGIN_STUDY_STARTTIME, ""); if (!startStr.equals("")) { long start = Long.parseLong(startStr); long current = Calendar.getInstance().getTimeInMillis(); Calendar s = Calendar.getInstance(); s.setTimeInMillis(start);//from ww w . ja v a 2s. co m s.set(Calendar.HOUR_OF_DAY, 3); s.set(Calendar.MINUTE, 0); s.set(Calendar.SECOND, 0); s.set(Calendar.MILLISECOND, 0); Calendar c = Calendar.getInstance(); c.setTimeInMillis(current); // c.set(Calendar.HOUR_OF_DAY, 12); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); start = s.getTimeInMillis(); current = c.getTimeInMillis(); return (int) ((current - start) / (24 * 60 * 60 * 1000)); } else { return -1; } }
From source file:Main.java
public static <T extends Number> List<Long> guardTypeAsLong(List<T> numbers) { List<Long> longs = new ArrayList<Long>(); for (int i = 0; i < numbers.size(); i++) { Number n = numbers.get(i); if (n instanceof Long) { longs.add(n.longValue());/*www. jav a 2s .c om*/ } else { longs.add(Long.parseLong(n.toString())); } } return longs; }
From source file:Main.java
/** Helper method - gets a named attribute's value as a <I>long</I>. @param pNodeMap The <I>NamedNodeMap</I>. @param strName Name of the attribute. @return Value of the attribute./* w w w .j ava 2s . com*/ */ public static long getAttributeLong(NamedNodeMap pNodeMap, String strName) throws ClassCastException, NumberFormatException { String strValue = getAttributeString(pNodeMap, strName); if (null == strValue) return Long.MIN_VALUE; return Long.parseLong(strValue); }
From source file:Main.java
public static String compress(String orderid) { if (orderid == null) { return ""; }// w ww . j a va 2s. c om String strNew1 = compressNumber(Long.parseLong(orderid.substring(4, 12)), 5); String strNew2 = compressNumber(Long.parseLong(orderid.substring(12, orderid.length())), 5); System.out.println(strNew1); System.out.println(strNew2); return strNew1 + strNew2; }
From source file:com.clican.pluto.common.util.TimeUtils.java
/** * ???/* ww w . j av a 2s . c om*/ * * @param expr * @return */ public static long getMillisionSecond(String expr) { if (StringUtils.isEmpty(expr)) { return -1; } if (expr.endsWith("ms")) { return Long.parseLong(expr.replaceAll(expr, "ms")); } else if (expr.endsWith("sec")) { expr = expr.replaceAll("sec", ""); return Long.parseLong(expr) * 1000; } else if (expr.endsWith("min")) { expr = expr.replaceAll("min", ""); return Long.parseLong(expr) * 1000 * 60; } else if (expr.endsWith("hour")) { expr = expr.replaceAll("hour", ""); return Long.parseLong(expr) * 1000 * 60 * 60; } else if (expr.endsWith("day")) { expr = expr.replaceAll("day", ""); return Long.parseLong(expr) * 1000 * 60 * 60 * 24; } else if (expr.endsWith("week")) { expr = expr.replaceAll("week", ""); return Long.parseLong(expr) * 1000 * 60 * 60 * 24 * 7; } else if (expr.endsWith("month")) { expr = expr.replaceAll("month", ""); return Long.parseLong(expr) * 1000 * 60 * 60 * 24 * 30; } else { throw new IllegalArgumentException("illegal expression arg"); } }