Java Date to Timestamp toDateTime(String timeStamp)

Here you can find the source of toDateTime(String timeStamp)

Description

to Date Time

License

Apache License

Declaration

public static String toDateTime(String timeStamp) 

Method Source Code

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

import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class Main {
    public static String toDateTime(String timeStamp) {
        try {//w w  w .jav  a2 s  .  co  m
            Long ts = Long.parseLong(timeStamp) * 1000;
            DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(new java.util.Date(ts));
        } catch (NumberFormatException e) {
            return "";
        }

    }

    public static String toDateTime(String timeStamp, String fmt) {
        try {
            Long ts = Long.parseLong(timeStamp) * 1000;
            DateFormat sdf = new SimpleDateFormat(fmt);
            return sdf.format(new java.util.Date(ts));
        } catch (NumberFormatException e) {
            return "";
        }

    }
}

Related

  1. timestamp(Date dateAndTime)
  2. timestampSec(Date date)
  3. TimestampToString(Date thisdate)
  4. toDate(String timeStamp)
  5. toDateStringFromResources(String timestamp)
  6. unixTimestampToDate(int timestamp)