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

private static long getLong(HashMap<String, String> values, String string) {
    return Long.parseLong(values.get(string));
}

From source file:Main.java

public static Date sixBytesToDate(byte[] bs) {
    if (bs.length != 6)
        return null;
    List<byte[]> listByte = cutByteArray(bs, 2);

    String intNum = String.valueOf(byteArrayToInt(listByte.get(1)));
    while (intNum.length() < 9) {
        intNum = "0" + intNum;
    }//from  w  ww . j a va 2s  .c o  m
    String shortNum = String.valueOf(byteArrayToShort(listByte.get(0)));
    long l = Long.parseLong(shortNum + intNum);
    return new Date(l);
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String getHMS(String time) {

    long timestamp = Long.parseLong(time);

    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    try {/*from www  .j  a v  a 2 s  . c o m*/
        String str = sdf.format(new Timestamp(timestamp));
        return str;

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return time;
}

From source file:Main.java

public static List<Long> transferToLongList(List doubleIdList) {
    List<Long> longIdList = new ArrayList<Long>();

    for (Object obj : doubleIdList) {
        if (obj instanceof Double) {
            try {
                Long tempId = ((Double) obj).longValue();
                longIdList.add(tempId);//from   ww  w .  j av  a 2  s . c o  m
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (obj instanceof Long) {
            longIdList.add((Long) obj);
        } else if (obj instanceof Integer) {
            longIdList.add(Long.parseLong(obj.toString()));
        }
    }

    return longIdList;
}

From source file:Main.java

public static Long extractValueId(Element element, String xpath) throws XPathExpressionException {
    XPath xpathObj = factory.newXPath();
    NodeList nodeList = (NodeList) xpathObj.compile(xpath).evaluate(element, XPathConstants.NODESET);

    for (int i = 0; i < nodeList.getLength(); i++) {
        String val = nodeList.item(i).getFirstChild().getNodeValue();
        return Long.parseLong(val);
    }// ww w  . j a v  a  2 s  .  c  o  m

    return null;
}

From source file:Main.java

public static long parseLong(String s) {
    try {//w  w  w  .  j av  a 2s  .com
        return Long.parseLong(s);
    } catch (NumberFormatException e) {
        return 0;
    }
}

From source file:Main.java

public static long parseLong(String num) {
    Long lon = -1l;//from  w ww . jav a2s. c om
    try {
        lon = Long.parseLong(num);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return lon;
}

From source file:Main.java

/**
 *  Gets the node value as long.//from www . jav  a  2  s  .c  om
 *
 *@param  node              Description of the Parameter
 *@return                   The nodeValueAsLong value
 *@exception  DOMException  Description of the Exception
 */
public final static long getNodeValueAsLong(Node node) throws DOMException {
    if (node != null) {
        node = node.getFirstChild();
        if (node != null)
            return Long.parseLong(node.getNodeValue());
    }
    return -1;
}

From source file:Main.java

public static int getTimeLeftFromNow(String time) {
    long target = 0;
    try {/*from   w w w  . ja va  2 s .co  m*/
        target = Long.parseLong(time);
    } catch (NumberFormatException e) {
        return 0;
    }
    long current = System.currentTimeMillis() / 1000;
    return (int) ((target - current) / 60 / 60 / 24 + 1);
}

From source file:AIR.Common.Utilities.JavaPrimitiveUtils.java

public static boolean longTryParse(String value, _Ref<Long> ref) {
    try {//ww  w .ja va 2  s. c o  m
        ref.set(Long.parseLong(value));
        return true;
    } catch (NumberFormatException exp) {
        return false;
    }
}