Java Second Calculate getSecond(String s)

Here you can find the source of getSecond(String s)

Description

get Second

License

Open Source License

Declaration

public static int getSecond(String s) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {

    public static String getSecond(Calendar cal) {
        return strLen(String.valueOf(cal.get(Calendar.SECOND)), 2);
    }//  w w  w.  j a v  a2  s .c  o m

    public static int getSecond(String s) {
        if (s == null || s.length() < 18) {
            return 0;
        }
        return Integer.parseInt(s.substring(16, 18));
    }

    private static String strLen(String s, int len) {
        if (isNullStr(s)) {
            s = "";
        }
        if (s.length() == 8) {
            return s;
        }
        for (int i = 0; i < len - s.length(); i++) {
            s = "0" + s;
            if (s.length() == 8) {
                break;
            }
        }
        return s;
    }

    private static boolean isNullStr(String s) {
        if (s == null || s.trim().length() <= 0) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. computeStartOfNextSecond(long now)
  2. getMillisecond(long num, int unit)
  3. getSecond(long t)
  4. nextSecond(int second)
  5. secondsLater(Integer seconds)