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 parseLongWithDefault(String s, long defValue) {
    if (s == null) {
        return defValue;
    }//from  www. j a v  a2 s .c o  m

    try {
        return Long.parseLong(s);
    } catch (NumberFormatException e) {
        return defValue;
    }
}

From source file:Main.java

public static String parseTime(String date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(Long.parseLong(date));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    return sdf.format(c.getTime());

}

From source file:Main.java

public static long getAttrLong(Node node, String attrName) {
    String s = getAttribute(node, attrName);
    if (s != null) {
        return Long.parseLong(s);
    }//  w w w . j  av a2  s .c o m
    return -1L;
}

From source file:Main.java

/**
 * takes a sqlite unix style representation and convert to java Date  
 *//*from ww w.j  a  va2 s  . c o  m*/
public static Date sqlite2javaDate(String sqliteDate) {
    return new Date(Long.parseLong(sqliteDate) * 1000L);
    //      return "(strftime('%s', "+fieldName+", 'unixepoch') * 1000) AS "+fieldName;
}

From source file:Main.java

public static Long getIndexFromName(String name) {
    int last = name.lastIndexOf("-");
    String aux = name.substring(last + 1);
    long r = 0;/*from ww w  .j a  v a  2s .  c o m*/
    try {
        r = Long.parseLong(aux);
        return new Long(r);
    } catch (Exception ex) {
        return null;
    }
}

From source file:Main.java

public static void latencyLog(String data) {
    data = data.substring(data.indexOf("time-") + 5);
    long started = Long.parseLong(data);
    long current = System.currentTimeMillis();
    Log.i("Latency", String.valueOf(current - started));

}

From source file:Main.java

public static String getDate(String time, String format) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date = new Date(Long.parseLong(time));
    return sdf.format(date);
}

From source file:Main.java

public static String formate2String(String mills) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Long l = Long.parseLong(mills);
    Date date;/*from w w  w . j  av  a2 s . co  m*/
    date = new Date(l);
    String format = sdf.format(date);
    return format;
}

From source file:Main.java

private static Object convertValType(Object value, Class<?> fieldTypeClass) {
    Object retVal;//from w  w w  .  j  av a  2 s  . com
    if (Long.class == fieldTypeClass || long.class == fieldTypeClass) {
        retVal = Long.parseLong(value.toString());
    } else if (Integer.class == fieldTypeClass || int.class == fieldTypeClass) {
        retVal = Integer.parseInt(value.toString());
    } else if (Float.class == fieldTypeClass || float.class == fieldTypeClass) {
        retVal = Float.parseFloat(value.toString());
    } else if (Double.class == fieldTypeClass || double.class == fieldTypeClass) {
        retVal = Double.parseDouble(value.toString());
    } else {
        retVal = value;
    }
    return retVal;
}

From source file:Main.java

public static String timestamp2Date(String time) {
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return sf.format(new Date(Long.parseLong(time) * 1000));
}