Java Now getTimeSubFromNowTime(String time)

Here you can find the source of getTimeSubFromNowTime(String time)

Description

get Time Sub From Now Time

License

Open Source License

Declaration

public static long getTimeSubFromNowTime(String time) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static long getTimeSubFromNowTime(String time) {
        int year = Integer.parseInt(getLocationCurrentDate().split("-")[0]);
        int month = Integer.parseInt(getLocationCurrentDate().split("-")[1]);
        int day = Integer.parseInt(getLocationCurrentDate().split("-")[2]);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {//  w ww .  j a v  a 2 s  .c  om
            Date date = format.parse(year + "-" + month + "-" + day + " " + time);
            Date now = new Date();
            return date.getTime() - now.getTime();
        } catch (ParseException e) {
            return 0;
        }

    }

    public static String getLocationCurrentDate() {
        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    }
}

Related

  1. getStringNowTime()
  2. getStringOfNowDate(String fFormatStr)
  3. getTimeNow()
  4. getTimeNow(Date theTime)
  5. getTimeNowAsString(String pattern)
  6. getValidDate(String unknownDate)
  7. isNowInInterval(String start, String end)
  8. makeUniqueName(final String[] knownNames, final String pattern)
  9. now()