Java Date to Timestamp toDateStringFromResources(String timestamp)

Here you can find the source of toDateStringFromResources(String timestamp)

Description

Convert timestamp string into a localised date string

License

Apache License

Parameter

Parameter Description
timestamp timestamp of format 20130124101010761

Declaration

public static String toDateStringFromResources(String timestamp) 

Method Source Code

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

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.Locale;

public class Main {
    /**// ww w.  j a  va 2 s  . c o  m
     * Convert timestamp string into a localised date string
     * @param timestamp      timestamp of format 20130124101010761
     * @return
     */
    public static String toDateStringFromResources(String timestamp) {

        //input
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");
        Date d = null;
        try {
            d = format.parse(timestamp);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        //output
        DateFormat formatter = DateFormat.getDateInstance(
                DateFormat.MEDIUM, Locale.getDefault());
        String s = formatter.format(d);

        return s;
    }
}

Related

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