Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static long getDuration(long beginTime) {
        return System.currentTimeMillis() - beginTime;
    }

    public static long getDuration(String beginTime) throws ParseException {
        return System.currentTimeMillis() - getTimeInLong(beginTime);
    }

    public static long getTimeInLong(String timeString) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss.SS");
        String base = "00:00:00.00";
        Date baseTime = format.parse(base);
        Date targetTime = format.parse(timeString);
        return targetTime.getTime() - baseTime.getTime();
    }
}