Java Time Parse getTimeStr(String date1, String date2)

Here you can find the source of getTimeStr(String date1, String date2)

Description

get Time Str

License

Open Source License

Declaration

public static String getTimeStr(String date1, String date2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

public class Main {
    public static String getTimeStr(String date1, String date2) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {//from  w  w w .j  av a 2  s.  co m
            long time = format.parse(date1).getTime() - format.parse(date2).getTime();
            long time1 = format.parse("1970-01-01 00:00:00").getTime() + time;
            return formatDate(new Date(time1), "HH:mm:ss");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static long getTime(String time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return format.parse("1970-01-01 " + time).getTime() - format.parse("1970-01-01 00:00:00").getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static String formatDate(Date date, String formatGeshi) {

        SimpleDateFormat format = new SimpleDateFormat(formatGeshi);

        return format.format(date);

    }
}

Related

  1. getTimeFileName(String suffix)
  2. getTimeFromGermanLocale(String timeString)
  3. getTimeFromJsToJava(String date)
  4. getTimeFromString(String time)
  5. getTimeList(String start, String end, int pitch)
  6. getTimeWithStr(String source, String pattern)
  7. getTimeX(String dateStr)
  8. isDateTime(String dateTime)
  9. isDateTime(String dateTime, String pattern)