Here you can find the source of toMsTime(final String value)
Parameter | Description |
---|---|
value | The string value to parse |
public static long toMsTime(final String value)
//package com.java2s; /*//w ww . java2s . co m * Copyright 2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.concurrent.TimeUnit; public class Main { /** * Converts the passed string to a ms timestamp. * If the parsed long has less than 13 digits, it is assumed to be in seconds. * Otherwise assumed to be in milliseconds. * @param value The string value to parse * @return a ms timestamp */ public static long toMsTime(final String value) { final long v = (long) Double.parseDouble(value.trim()); return digits(v) < 13 ? TimeUnit.SECONDS.toMillis(v) : v; } /** * Determines the number of digits in the passed long * @param v The long to test * @return the number of digits */ public static int digits(final long v) { if (v == 0) return 1; return (int) (Math.log10(v) + 1); } }