Java Timestamp Format getFormattedDate(String timestamp)

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

Description

get Formatted Date

License

Apache License

Declaration

public static Date getFormattedDate(String timestamp) throws ParseException 

Method Source Code

//package com.java2s;
/**//ww  w . j  av  a 2  s  .co  m
 * Created as part of the StratusLab project (http://stratuslab.eu),
 * co-funded by the European Commission under the Grant Agreement
 * INSFO-RI-261552.
 *
 * Copyright (c) 2011
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

public class Main {
    private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

    public static Date getFormattedDate(String timestamp) throws ParseException {
        return getDateFormat().parse(timestamp);
    }

    public static String getFormattedDate(Date date) {
        return getDateFormat().format(date);
    }

    private static DateFormat getDateFormat() {
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        format.setLenient(false);
        format.setTimeZone(TimeZone.getTimeZone("UTC"));

        return format;
    }
}

Related

  1. friendlyTimestampFormat()
  2. friendlyTimestampFormat()
  3. getCalendar(String timeStamp, final String dateFormat)
  4. getEpochTime(String dateTimeStamp, SimpleDateFormat dateFormat)
  5. getFormatForTimestamp( final Calendar now, final Calendar timestamp)
  6. getFormattedDateFromTimestamp(long timestamp)
  7. getFormattedTime(long timestamp, String format)
  8. getFormattedTimestamp()
  9. getFormattedTimestamp(@Nonnull Date date)