Java Hour Format formatDateTime(String dateTime)

Here you can find the source of formatDateTime(String dateTime)

Description

format Date Time

License

Open Source License

Declaration

public static String formatDateTime(String dateTime) 

Method Source Code

//package com.java2s;
/*/*  w w w .ja  v a  2 s  . c om*/
 *  SSHTools - Globus Online Tool
 *
 *  Copyright (C) 2013 Siew Hoon Leong
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  You may also distribute it and/or modify it under the terms of the
 *  Apache style J2SSH Software License. A copy of which should have
 *  been provided with the distribution.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  License document supplied with your distribution for more details.
 *
 */

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

import java.util.Date;

public class Main {
    public static String formatDateTime(String dateTime) {
        try {
            dateTime = dateTime.substring(0, 22) + dateTime.substring(23, 25);
            String pattern = "yyyy-MM-dd HH:mm:ssZ";
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            Date date = sdf.parse(dateTime);
            String newPattern = "dd MMM yyyy h:mm aaa zzz";
            SimpleDateFormat myFormat = new SimpleDateFormat(newPattern);
            return myFormat.format(date);

        } catch (ParseException e) {
        }

        return dateTime;
    }
}

Related

  1. formatDateTime(java.util.Date date)
  2. formatDateTime(java.util.Date date)
  3. formatDateTime(java.util.Date paramDate)
  4. formatDateTime(String date)
  5. FormatDateTime(String dateString)
  6. formatDateTime(String strDateTime, String strFormat)
  7. formatDateTime12(String dateStr)
  8. formatDateTime24()
  9. formatDateTimeForSolr(Date d)