Help parse date : MMM dd, yyyy hh:mm:ss a zzz

I don't know how to get this to work. It parses but give me a wrong date all the time:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateParserTest {
    public DateParserTest() {
    public static void main(String [] argv) {
        //Nov 17, 2006 1:00:00 PM MST<
        String sdate = "Nov 17, 2006 1:00:00 PM MST";
        Date date = extractDate(sdate);
        System.out.println("Orig date: " + sdate);
        System.out.println("Current date: " + date.toString());
    public static Date extractDate(String data) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy hh:MM:ss a zzz"); //zzz
        try {
            Date date = sdf.parse(data);
            return date;
        } catch (ParseException ex) {
            ex.printStackTrace();
            return null;
}

Instead of:
"MMM dd, yyyy hh:MM:ss a zzz"you should have:
"MMM dd, yyyy hh:mm:ss a zzz"Minutes are lowercase m's

Similar Messages

  • How to convert Date format from yyyy mm dd   to   dd mmm yyyy in ADF

    Hi,
    I have Date Format in Data Base as yyyy mm dd, but in the UI I want to display the format as dd mmm yyyy, which code I have to write to get the required format in JDev 11.1.2.3

    Hi,
    Use converter : &amp;lt;af:convertDateTime&amp;gt;
    See also : convertDateTime Demo
    -Arun

  • How to parse system date to return Date and in yyyy-MM-dd format?

    DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
    java.util.Date date = new java.util.Date ();
    String dateStr = dateFormat.format (date);
    try{
    Date date2 = dateFormat.parse (dateStr);
    }catch(ParseException pe){
    pe.printStackTrace();
    Actually, After parsing the date from string, again it is converted into dfault format i.e. 21 Jan 00.00.00 etc...
    But I want this parsing date in yyyy-MM-dd format and again to return date.
    Can anybody tell me how to do this?

    DateFormat dateFormat = new SimpleDateFormat
    ("yyyy-MM-dd");
    java.util.Date date = new java.util.Date ();
    String dateStr = dateFormat.format (date);
    try{
    Date date2 = dateFormat.parse (dateStr);
    }catch(ParseException pe){
    pe.printStackTrace();
    Actually, After parsing the date from string, again
    it is converted into dfault format i.e. 21 Jan
    00.00.00 etc...
    But I want this parsing date in yyyy-MM-dd format and
    again to return date.
    Can anybody tell me how to do this?A Date object does not have a format, it represents a moment in time. You can use SimpleDateFormat to return a String representing that moment in time in many formats - this does not change the Date object to have that format (which it cannot since it does not contain a format).

  • How to convert DateFormat mm/dd/yy to mmm dd yyyy

    Hello, I want to convert from DateFormat mm/dd/yy to a new Date Format that looks like the same date except for the month showing in numbers.
    That is, 09/14/07 would change to Sep 14 2007.
    I've tried to use SimpleDateFormat, where I've specified my DateFormat to MM dd yyyy, but that hasn't helped. Your help will be very much appreciated.

    You want this:
    package cruft;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;
    * DateFormatDemo
    * User: Michael
    * Date: Sep 14, 2007
    * Time: 7:21:05 PM
    public class DateFormatDemo
       public static void main(String[] args)
          DateFormat inDateFormat = new SimpleDateFormat("MM/dd/yy");
          inDateFormat.setLenient(false);
          DateFormat outDateFormat = new SimpleDateFormat("MMM-dd-yyyy");
          outDateFormat.setLenient(false);
          for (int i = 0; i < args.length; ++i)
             try
                Date date = inDateFormat.parse(args);
    System.out.println("in : " + inDateFormat.format(date));
    System.out.println("out: " + outDateFormat.format(date));
    catch (ParseException e)
    e.printStackTrace();

  • Need help in date formatting

    Hi,
    I need to print date in the following format:
    Jan 21, 2007
    11:23 AM 21/01/2007
    21-01-2007 18:23
    Now as per condition of assignment the year, month, day and hour, min, sec all are entered as separate integer values.
    my code:
    import java.util.*;
    import java.text.*;
    public class stringToDate
    // Integer value of date and time variables
    int day=21;
    int month = 1;
    int year=07;
    int hour=18;
    int min=23;
    int sec=14;
    // Converting integer value into date
    public void convertIntoDate()
         String strTmp= day+"/"+month+"/"+year+" "+hour+":"+min+":"+sec;
         System.out.println("String: " + strTmp);
         DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
         try
              Date outDate = dateFormat.parse(strTmp);
              System.out.println("Converted: " + dateFormat.format(outDate));
         catch(Exception e){ System.out.println("Exception: " + e);}
    public static void main(String args[]) {
         stringToDate dF = new stringToDate();
         dF.convertIntoDate();
    }Now as per my code i am able to print in the following format:
    String: 21/1/7 18:23:14
    Converted: 21/01/0007 18:23:14
    But if i try to print in other formats it gives me following error message:
    Exception: java.text.ParseException: Unparseable date: "21/1/07"
    Please help me....

    vinee wrote:
    Hi,
    I tried different output format but still i'm facing the same issue
    Following the complete code and error message....
    import java.util.*;
    import java.text.*;
    public class stringToDate
    // Integer value of date and time variables
    int day=21;
    int month = 1;
    int year=07;
    int hour=18;
    int min=23;
    int sec=14;
    // Converting integer value into date
    public void convertIntoDate()
    DateFormat dateFormat;
    Date outDate=null;
    String strTmp= day+"/"+month+"/"+year+" "+hour+":"+min+":"+sec;
    System.out.println("Entered string for date: " + strTmp);
         // Format 01/01/0070 15:24:14
         dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
         try
         outDate = dateFormat.parse(strTmp);
         System.out.println("Converted into Date(dd/MM/yyyy HH:mm:ss): " + dateFormat.format(outDate));
         catch(Exception e){ System.out.println("Exception in format 1: " + e);}
         // Format Jan 21, 2007
         dateFormat = new SimpleDateFormat("EEE, MMM d, ''yyyy");
         try
         outDate = dateFormat.parse(strTmp);
         System.out.println("Converted into Date(EEE, MMM d, ''yyyy): " + dateFormat.format(outDate));
         catch(Exception fe)
         {System.out.println("Exception in format 2: " + fe);}
    public static void main(String args[]) {
              stringToDate dF = new stringToDate();
              dF.convertIntoDate();
    }Following is the error message:
    Entered string for date: 21/1/7 18:23:14
    Converted into Date(dd/MM/yyyy HH:mm:ss): 21/01/0007 18:23:14
    Exception in format 2: java.text.ParseException: Unparseable date: "21/1/7 18:23:14"
    Now as per the above error message format one is working fine but format 2(// Format Jan 21, 2007) have some issues...kind suggest.
    Edited by: vinee on Oct 2, 2008 4:23 AMPlease re-read my last reply.
    Once again : see [http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html]
    And your:
    int year=07; // should be:
    int year=2007;

  • How can i get todays date as an yyyy-MM-dd format instead of Time stamp

    how can i get todays date as an yyyy-MM-dd format instead of Time stamp,i try to do it in the fallowing way
    <code>
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date d = new java.util.Date();
              String s = d+"";
    Calendar cal1 = Calendar.getInstance();
         try{
         cal1.setTime(sdf.parse(s));
    }catch(Exception e){}
    </code>
    but i could not able to get,it throws error as an java.text.ParseException: Unparseable date: "Thu Jan 24 11:43:32 EST 2002" ,pl suggest me any solution.any help would be appreciated.
    Regards.

    Does string s have to end with ""?
    Try doing sdf.format(d) instead.

  • Parsing date from JSON response

    Is there any helper method to parse date time value being returned in JSONResponse to get java.util.Date. For example, 2012-06-26T15:51:59.078-05:00. I have done simple java method using SimpleDateFormat, but that does not handle all possible formats. Anyone has ideas on libraries that can be used for this purpose?
    Chandresh

    Oh I see you receive different formats from different services, who's backend you can not modify.
    I found this, it should help you get the job done:
    http://stackoverflow.com/questions/4024544/how-to-parse-dates-in-multiple-formats-using-simpledateformat
    Note however, that his problem is only relatively simplistic, yours on the other hand seems to be one of a kind where you have to be set up a pretty nifty algorithm taking care of all the different possible formats. That being said, there is no method which can parse ANY format you throw at it. you must write one yourself which knows which possible formats to expect.
    If its only those two formats you can expect:
    2012-06-26T15:51:59.078-05:00
    2012-06-26T15:51:59-05:00
    it should be an easy try-catch construct within a helper method. just be sure to use the right letters when setting up your SimpleDateFormat parse object, it's case sensitive and one quickly gets lost in all those letters.
    Edit:
    Again this should do the trick:
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
    Just make sure you remove the last ":" from the JSONString (simple string manipulation) and then have two cases
    //removing last ":" from JSONString
    //====
    //Parsing string to date or gregCalendar
    GregorianCalendar time= new GregorianCalendar();
    try{
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
    time.setTime(sdf.parse(JSONString));
    catch{
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
    time.setTime(sdf2.parse(JSONString));
    Edited by: Pascal B on 05.07.2012 04:50
    Edited by: Pascal B on 05.07.2012 04:55

  • Parse date

    Hi all,
    Parse the format "Jul 1, 2t00u3" gives no exception. Normally if a year is not a digit then an exception will be generated, which is not the case in the following example.
    input: date format with year "2t00u3"
    DateFormat df = DateFormat.getDateInstance();
    try {     
         System.out.println(df.parse("Jul 1, 2t00u3"));
    } catch (ParseException e) {               
         e.printStackTrace();
    output:Sat Jul 01 00:00:00 CET 0002
    How can I get an exception instead of the above output ?
    Thanks,
    Said

    Firstly, you shouldn't rely on your default date format, because another user might use a different default (my computer DOES throw an exception when I run your code). It is better to provide the format that you want to parse by using the subclass SimpleDateFormat like this:     DateFormat df = new SimpleDateFormat("MMM d, yyyy");
         try {
             System.out.println(df.parse("Jul 1, 2t00u3"));
         } catch (ParseException e) {
             e.printStackTrace();
         }Secondly, if you look up the Javadocs for DateFormat.parse() it says:Parses text from the beginning of the given string to produce a date.
    The method may not use the entire text of the given string.Note that trailing comment about not using the entire String - that's what is causing your problem.
    One solution is to accept your date in a more suitable format such as mm-dd-yyyy and then you can more easily check that each character in the source String is the right format, using String charAt() and Character.isDigit() and stuff like that, or just check the length of the input String
    Another solution, is to reformat the result back into a String and see if it matches the original input.          String testDate = "Jul 1, 2t00u3";
              DateFormat df = new SimpleDateFormat("MMM d, yyyy");
              df.setLenient(false);
              Date date = null;
              try {
                   date = df.parse(testDate);
              } catch (ParseException e) {
                   e.printStackTrace();
              if (testDate.equalsIgnoreCase(df.format(date))) {
                   System.out.println("Was the same when reconverted");
              } else {
                   System.out.println("Wasn't the same");
              }You should also consider whether you should setLenient(true) or setLenient(false) on your SimpleDateFormat - although unfortunately it doesn't solve the particular problem you're seeing
    Regards,
    Tim

  • How do I create individual xml files from the parsed data output of a xml file?

    I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? Thanks in advance for your help.
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println("Template" + ": " +templateElement.getAttribute("name")+ ".xml");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

  • Convertinf Date format from YYYY-MM-DD to MMDDYYYY

    Hi Experts,
              I want to convert  date format from yyyy-MM-dd  to MMDDYYYY ( i am using this format in the file strucure),
             i tryed using date tranfer funcion source as yyyy-MM-dd and target as yyyyMMdd this is working fine.
    i tryed using date tranfer funcion source as yyyy-MM-dd and target as MMddyyyy this is giving error.
    Please help me out,
    Thanks,
    Dhanush

    Hi,
    From the error it looks like the date value is coming as blank in the source. please give the date in the same format as you have provided in datetrans function and test it again. It will work.
    It might be possible that there are some other date fields in your source where you are not passing any value and using datefunction. please look carefully at all the source structure and data.
    thanks
    amit
    reward point if suggestion works

  • Date Validation In YYYY/MM/DD Format

    Hi All....
                I have developed A conversion Program in which I have struck up with the code of validating the date format in YYYY/MM/DD Format. I should Append the records to the database table T558B in which all the other validations are done. pls help me......

    Hi,
    Use in ABAP this sentence:
       SET COUNTRY t005x-land.
    In table T005X you have in field DATFM the formats for date. (or in tcode OY01)
    I hope this helps you
    Regards
    Eduardo
    Edited by: E_Hinojosa on Feb 14, 2011 5:08 PM

  • Input is 10 digit date (dd/mm/yyyy) some times instead of date they will se

    Hi Experts,
    requirement is
    input is 10 digit date (dd/mm/yyyy) some times instead of date they will send as space(10 digit). it should not fail in PI.
    kindly help me on this.
    regards
    Elton

    HI,
    I have given like
    if input equals to constant(space)
    then constant(space)----
    > here you have to pass constant date / system date
    else
    input
    input -> constant(10 space) -> equals ->if ->
    then -> constant(date) ->target
    else -> input->target filed
    thanks,

  • Why is this date{MM-DD-YYYY} not a valid pattern?

    I'm tyring to define a new date pattern, date{MM-DD-YYYY}, in Adobe Desinger 7 and it kept saying the pattern is not valid. Please help.

    Never mind. I got it.

  • Need Help with Dates

    I am printing a calendar and certain events will be helds on certain dates.
    One can edit the event if it has not passed the date. Events in the past can be viewed but not edited.
    When I query the database the date must be formatted dd-MMM-yy
    I am able to get today's date by doing this:
    java.util.Date today = new java.util.Date();
    String formatString = "dd-MMM-yy";
    SimpleDateFormat sdf = new SimpleDateFormat(formatString);
    String today_str = sdf.format(today);
    My code for printing the calendar: I left out some of the table formatting in the JSP page.
    GregorianCalendar d = new GregorianCalendar();
    int today = d.get(Calendar.DAY_OF_MONTH);
    int month = d.get(Calendar.MONTH);
    d.set(Calendar.DAY_OF_MONTH,1);
    int weekday = d.get(Calendar.DAY_OF_WEEK);
    for(int i = Calendar.SUNDAY; i < weekday; i++)
    out.print("<td> </td>");
    do {
    int day = d.get(Calendar.DAY_OF_MONTH);
    out.print("<td>" + day + "</td>");
    String formatString = "dd-MMM-yy";
    SimpleDateFormat sdf = new SimpleDateFormat(formatString);
    //if(event exists on this day
    // Get results
    // print link for viewing
    // if (after today) print link for edit
    if(weekday == Calendar.SATURDAY)
    out.println("</tr><tr valign=top>");
    d.add(Calendar.DAY_OF_MONTH,1);
    weekday = d.get(Calendar.DAY_OF_WEEK);
    } while(d.get(Calendar.MONTH) == month);
    if(weekday != Calendar.SUNDAY)
    System.out.println();
    The part I need help on is this:
    //if(event exists on this day
    // Get results
    // print link for viewing
    // if (after today) print link for edit
    I'm looping through each day of the month to print the days. I have the month, day, year as integers. How can I create a date object out of that and compare it to today's date to test if it's before or after today???
    All the function in the Date class that I think would do this have been deprecated.

    Need Help with Dates
    Here is some information about dates:
    There are many edible palm fruits, and one of the most widespread and favored of these is the data (Phoenix dactylifera). Dates were cultivated in ancient land from Mesopotamia to prehistoric Egypt, possibly as early as 6000 B.C. Then--as now--dates were a staple for the natives of those dry regions. Much later, Arabs spread dates around northern Africa, and dates were introduced into California by the Spaniards in 1765, around Mission San Ignacio.
    The date prefers dry, hot climates, because date fruits are injured at temperatures of 20 degrees F, and the damp climate of the California coast was not favorable for fruit production. In the mid-1800s, the date industry developed in California's hot interior valleys and in Arizona. Now the date industry in the United States is localized mostly in the Coachella Valley, where the sandy soils permit the plants to be deeply irrigated. Today the new varieties, mostly introduced in this century, produce about 40 million pounds of dates per annum, or over 60% of the dates consumed in this country. The rest are imported mainly from Persia. According to one survey, about one million people are engaged entirely in date palm cultivation worldwide.
    Hope that helps.

  • Parsing Date with SimpleDateFormat

    Hi,
    In my application, i want to parse date which is in String format.
    The format of Date in String is "yyyyMMdd'T'HHmmss.SSS'Z'" (ex:- 20031201T100116.000Z).
    //Happy Case - Input Param "20031201T100116.000Z"
    //Output : 2003-12-01 10:01:16.0 is the expected output ------- works well.
    //Exception case Input param Value "00000000T000000.000Z"
    But the above case breaks as the expected output is "0000-00-00 00:00:00 ". But the output what i get is
    "0002-11-30 00:00:00.0"
    Greatly appreciate your inputs...,
    Here is my code for the above stated case....
    private static void printDateFormat(String str) throws Exception
    String format = "yyyyMMdd'T'HHmmss.SSS'Z'"; //Desired Format
    ParsePosition pos = new ParsePosition(0);
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date date = sdf.parse(str, pos);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    System.out.println("[After Formatting]" + date.toString());
    java.sql.Timestamp ts = new java.sql.Timestamp(cal.getTime().getTime());
    System.out.println(ts.toString());
    Thanks !
    Priya.Jlus
    IIMS-NZ.

    SimpleDateFormat is set to lenient date parsing by default, so it's trying it's best to come up with an actual date for 0000-00-00 (what would you say a 'zero' month should be?). You can prevent this "approximation" by using "setLenient(false)", but then you will get a null Date reference for non-parseable dates like the one you're using.
    The bottom line is that you're going to have to do some validation for the user input and handle exceptional conditions.
    Hope this helps! :o)

Maybe you are looking for

  • My IDML file saved in Indesign CC won't open in Indesign 6

    Hello. I am on trial of Indesign CC, and exported a file to an IDML trying to open it on the school computer since they only have previous versions of Indesign. When I try to open my file that I worked on at home in Indesign CC, it won't open in Inde

  • Converting Photos

    Trying to prepare a small newspaper ad. Is there a way, after dragging a color photo into Draw or Paint, to convert it to Black & White or Grayscale ? I know I can go through iPhoto...just looking for a quick way in AW. Thanks, Lenny

  • Cloning the Oracle Database Server which has Grid 11.2.03 and DB 11.2.0.3

    Hi DBA's, Did anybody came across cloning a database servers? If i have the OFA for Grid and DB homes i.e /u01/app/oracle so after clone it will be the same across all servers. So the inventory structure will be same also. After cloning changing the

  • Problem getting the Kuler panel for Ps CC 2014

    Hey everybody. I think the title makes my problem clear. I am trying to get the new Kuler panel for updated Ps CC 2014 from here https://creative.adobe.com/addons/products/2507 But I cant find the download button. It looks like i have the CS6 and off

  • What is struts-faces really aim for ?

    I don't really understand what is struts-faces aim for ? I explain myself : Supposing that on the first hand I've got an "old" application using struts that I would like to extend, but on the other hand I wish I could use JSF for my extends... I'll t