Example usage for java.lang Long parseLong

List of usage examples for java.lang Long parseLong

Introduction

In this page you can find the example usage for java.lang Long parseLong.

Prototype

public static long parseLong(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal long .

Usage

From source file:Main.java

public static long getWaitSeconds(Context context) {
    String v = PreferenceManager.getDefaultSharedPreferences(context).getString("key_wait_seconds", "10");
    try {//from ww w .  j av a  2s .c  o  m
        return Long.parseLong(v) * 1000;
    } catch (Exception ex) {
        ex.printStackTrace();
        return 10 * 1000;
    }
}

From source file:Main.java

public static final long[] collection2longArray(Collection<Object> collection) {
    long[] array = new long[collection.size()];
    int index = 0;
    for (Object value : collection) {
        try {/*from w w w  .  j  ava 2s. co  m*/
            array[index] = Long.parseLong(String.valueOf(value));
            index++;
        } catch (Exception e) {
        }
    }
    return array;
}

From source file:Main.java

public static String getBalanceDisplay(String bal, int floatSize) {
    if ("".equals(bal)) {
        return "";
    } else {/*from   www  . j  a va 2  s  .  c om*/
        long amount = Long.parseLong(bal);
        NumberFormat format = NumberFormat.getInstance();
        if (NumEmpty == amount)
            return "";
        if (floatSize < 0) { // error input
            return Long.toString(amount);
        }
        if (floatSize == 2) {
            boolean zs = true;
            if (amount < 0) {
                zs = false;
                amount = -amount;
            }
            long m = amount / 100;
            long f = amount - m * 100;
            return (zs ? "" : "-") + format.format(m) + "." + (f > 9 ? Long.toString(f) : "0" + f);
        } else if (floatSize == 0) {
            return format.format(amount);
        } else { // error input
            return format.format(amount);
        }
    }
}

From source file:Main.java

/**
 * Times": "(1425956629171)" to timeInMillis
 * @param string/*from   w  ww. j a  v  a 2s.c  o  m*/
 * @return
 */
public static long parseToTimeInMillis(String string) {
    int start = string.indexOf("(") + 1;
    int end = string.indexOf(")");
    String timeString = string.substring(start, end);

    long timeMillis = Long.parseLong(timeString);
    return timeMillis;
}

From source file:Main.java

public static String toDate(Long aLong) {
    String beginDate = String.valueOf(aLong);
    @SuppressLint("SimpleDateFormat")
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    return sdf.format(new Date(Long.parseLong(beginDate)));
}

From source file:Main.java

public static String timeToDateString(String time) {
    SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date = "";
    try {//w ww.j a v a2s.c  o m
        date = simpleFormat.format(new Date(Long.parseLong(time)));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return date;
}

From source file:Main.java

public static Long stringToLong(String str) {
    if (str == null) {
        return null;
    } else {// ww w.  j  a  v  a2 s.c  o  m
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for long");
                    return null;
                }
                return Long.valueOf(d.longValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to long, caught NumberFormatException <" + nfe2.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:Main.java

public static long str2Long(String obj, Long defValue) {
    try {//from  w  w w.ja v  a2 s .c  o  m
        if (TextUtils.isEmpty(obj))
            return defValue;
        return Long.parseLong(obj);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return defValue;
}

From source file:Main.java

public static long getVideoDurationInMillis(String videoFile) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(videoFile);//  w w  w.j a v a2  s .c  om
    String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
    long timeInmillisec = Long.parseLong(time);
    retriever.release();
    return timeInmillisec;
}

From source file:Main.java

public static Date parseISO8601Date(String s) throws ParseException {
    synchronized (mISO8601DateFormat) {
        Date date = new Date(Long.parseLong(s));
        return date;
        // return mISO8601DateFormat.parse(s);
    }// www  .  j a  va  2s . c  o  m
}