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 HowLongAgo(String timestamp) {
    Long tempo;/*from  ww w.j a v a  2  s  .  com*/
    try {
        tempo = Long.parseLong(timestamp);
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }

    java.util.Date Now = new java.util.Date();

    long diff = (Now.getTime() - tempo);
    if (diff < 0)
        return 0;

    diff /= 1000;

    return diff;

}

From source file:Main.java

public static String msToDate(String ms) {
    long miliseconds = Long.parseLong(ms);
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy hh:mm aaa");

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(miliseconds);/* w w w  . j  a  v a 2 s  . c  o m*/
    return sdf.format(c.getTime());
}

From source file:Main.java

public static String getDate(String pubDate) {
    Date date = new Date(Long.parseLong(pubDate) * 1000);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    return simpleDateFormat.format(date);
}

From source file:Main.java

private static long safeParseLong(String s) {
    try {//from   w w w  .j  av  a2s  .  co m
        return Long.parseLong(s);
    } catch (Exception e) {
        return default_value;
    }
}

From source file:Main.java

public static Long parseLong(String str) {
    if (isEmpty1(str)) {
        return null;
    } else {//from  w  w  w.j ava2s . c o  m
        return Long.parseLong(str);
    }
}

From source file:Main.java

public static long toLong(String s, long def) {
    if (s == null) {
        return def;
    }/*from www  .ja v a  2 s  .co m*/
    try {
        return Long.parseLong(s);
    } catch (NumberFormatException e) {
        return def;
    }
}

From source file:Main.java

public static Long stringToInt64(String str) {
    Long rst = null;//  w w  w  .jav  a2  s .c o  m
    try {
        rst = Long.parseLong(str);
    } catch (Exception e) {
        // do nothing
    }
    return rst;
}

From source file:Main.java

public static String amount2String(String amount) {
    String temp = amount.replace(".", "").replace(",", "");
    return String.format("%012d", Long.parseLong(temp));
}

From source file:Main.java

public static String formatSize(String strSize) {
    try {/*w w w .j  a v a  2  s  . com*/
        long size = Long.parseLong(strSize);
        String sizePref = "B";
        if (size >= 1073741824) {
            size = size / 1073741824;
            sizePref = "GB";
        } else if (size >= 1048576) {
            size = size / 1048576;
            sizePref = "MB";
        } else if (size >= 1024) {
            size = size / 1024;
            sizePref = "KB";
        }

        return "Size: " + size + " " + sizePref;
    } catch (NumberFormatException e) {
        return "";
    }
}

From source file:Main.java

public static Calendar convertCalendar(String milliSeconds) {

    Long mMilliSeconds = 0L;//w w w .  j av a2 s  .co  m

    mMilliSeconds = Long.parseLong(milliSeconds);

    Calendar mCalendarEvent = Calendar.getInstance();
    mCalendarEvent.setTimeInMillis(mMilliSeconds);
    return mCalendarEvent;

}