Java Long Number to Date converteDataStr2Long(String str)

Here you can find the source of converteDataStr2Long(String str)

Description

converte Data Str Long

License

Apache License

Declaration

public static long converteDataStr2Long(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static long converteDataStr2Long(String str) {
        Date date = new Date();

        String temp = str.substring(0, 4);
        date.setYear(Integer.valueOf(temp).intValue() - 1900);
        temp = str.substring(5, 7);/*from  w  ww.j a  v a 2s  .  c o m*/
        date.setMonth(Integer.valueOf(temp).intValue() - 1);
        temp = str.substring(8, 10);
        date.setDate(Integer.valueOf(temp).intValue());
        temp = str.substring(11, 13);
        date.setHours(Integer.valueOf(temp).intValue());
        temp = str.substring(14, 16);
        date.setMinutes(Integer.valueOf(temp).intValue());
        temp = str.substring(17, 19);
        date.setSeconds(Integer.valueOf(temp).intValue());
        return date.getTime() / 1000;
    }

    public static long getTime(String dateStr) {
        long time = -1;
        String format = "yyyy-MM-dd HH:mm:ss";
        Date date = getDate(dateStr, format);
        if (date != null) {
            time = getDate(dateStr, format).getTime();
        }
        return time;
    }

    public static Date getDate(String dateStr, String formatString) {
        Date date = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(formatString);
            date = sdf.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    public static Date getDate(String dateStr) {
        return getDate(dateStr, "yyyy-MM-dd HH:mm:ss");
    }
}

Related

  1. convertDate(Long uTime, SimpleDateFormat dateFormat)
  2. convertDateFromLong(Long val)
  3. convertDateFromTimeStamp(long timeStamp, String dateFormat)
  4. convertDateToString(long value)
  5. convertDecimal(long l)
  6. convertFromLongToString(SimpleDateFormat fm, long date)
  7. convertHours2DatetimeString(long nodeTaskCompleteTime)
  8. convertMillisecondToDateTimeString(long millisecond, String mark)
  9. convertMMDDYYYYToDate(String date)