Java Hour Format formatDateTime12(String dateStr)

Here you can find the source of formatDateTime12(String dateStr)

Description

format Date Time

License

Open Source License

Declaration

public static void formatDateTime12(String dateStr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

import java.util.Date;

import java.util.TimeZone;

public class Main {
    public static void formatDateTime12(String dateStr) {
        // format 12 hours time to 24 hours time
        SimpleDateFormat parseFormat = new SimpleDateFormat("dd/mm/yy HH:mm:ss zz");
        SimpleDateFormat displayFormat = new SimpleDateFormat("dd/mm/yy hh:mm:ss a zz");
        // time zone
        String[] tz = dateStr.split(" ");
        TimeZone firstTime = TimeZone.getTimeZone(tz[tz.length - 1]);
        parseFormat.setTimeZone(firstTime);
        displayFormat.setTimeZone(firstTime);
        Date date = null;//  ww w  .  j  a  v  a2 s.com
        try {
            date = parseFormat.parse(dateStr);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(parseFormat.format(date) + " = " + displayFormat.format(date));

    }
}

Related

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