SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S") not parsing as expected

The date I am getting back when parsing with SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S") seems wrong.
I get the following output when I run the sample code below. I would expect the time to be 13:37:24 not 13:50:41.
Thanks
Tue Jul 28 13:50:41 EDT 2009
2009-07-28T13:50:41.383
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ParseDate {
    public static void main(String[] args) throws Exception {
        final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.S";
        String userDate = "2009-07-28T13:37:24.797383";
        SimpleDateFormat dfIn = new SimpleDateFormat(DATE_FORMAT);
        Date d = dfIn.parse(userDate);
        System.out.println(d);
        DateFormat dfOut = new SimpleDateFormat(DATE_FORMAT);
        Date dOut = d;
        System.out.println(dfOut.format(dOut));
}

In other words that "24.797383" is NOT parsed as if it were 24 and 797383/1000000 seconds (which is what I assume you're assuming). It's parsed as 24 seconds and 797383 ms.

Similar Messages

  • SimpleDateFormate has problem in ar_EG Locale

    Hi all,
    This code fails when the machine locale is ar_EG(known Java bug [ http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4823811] )
    try{
    SimpleDateFormat st =new SimpleDateFormat();
    st.applyPattern("yyyy-MM-dd-HH.mm.ss");
    st.parse("2002-12-20-12.18.20");
    I am going to use below code as a workaround and I want to make sure it will not fail in any OS with any Locale .Specially OS does not contain Locale_US (Since I use it )
    SimpleDateFormat st =new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss",Locale.US);
    st.parse("2002-12-20-12.18.20");
    Thanks in advance,
    rona

    Hi all,
    This code fails when the machine locale is ar_EG(known
    Java bug [
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4823
    11] )
    try{
    SimpleDateFormat st =new SimpleDateFormat();
    st.applyPattern("yyyy-MM-dd-HH.mm.ss");
    st.parse("2002-12-20-12.18.20");
    I am going to use below code as a workaround and I
    want to make sure it will not fail in any OS with any
    Locale .Specially OS does not contain Locale_US (Since
    I use it )I don't understand this part.
    >
    SimpleDateFormat st =new
    SimpleDateFormat("yyyy-MM-dd-HH.mm.ss",Locale.US);
    st.parse("2002-12-20-12.18.20");
    Thanks in advance,
    ronaThe constructor which takes Locale as its second arg works on Sun JDK + Linux.

  • Facing issue in suggested meeting time in ews-java-api

    Hi,
    I have a meeting room id , and i want to get Free and Busy schedule of the meeting room , below is the code i am using
    List<AttendeeInfo> attendees = new ArrayList<AttendeeInfo>();
    attendees.add(new AttendeeInfo([email protected]));
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startDate = formatter.parse("2015-03-03 00:00:00");
    Date endDate = formatter.parse("2015-03-05 00:00:00");
    // Call the availability service.
    GetUserAvailabilityResults results = exchangService.getUserAvailability(
    attendees,
    new TimeWindow(startDate, endDate),
    AvailabilityData.FreeBusyAndSuggestions);
    // Output attendee availability information.
    int attendeeIndex = 0;
    for (AttendeeAvailability attendeeAvailability : results.getAttendeesAvailability()) {
    System.out.println("Availability for " + attendees.get(attendeeIndex).getSmtpAddress());
    //if (attendeeAvailability.getErrorCode() == ServiceError.NoError) {
    for (CalendarEvent calendarEvent : attendeeAvailability.getCalendarEvents()) {
    System.out.println("Calendar event : "+ calendarEvent.getFreeBusyStatus().toString());
    System.out.println(" Start time: " + calendarEvent.getStartTime().toString());
    System.out.println(" End time: " + calendarEvent.getEndTime().toString());
    if (calendarEvent.getDetails() != null)
    System.out.println(" Subject: " + calendarEvent.getDetails().getSubject());
    // Output additional properties.
    attendeeIndex++;
    for (Suggestion suggestion : results.getSuggestions()) {
    System.out.println("Suggested day: " + suggestion.getDate().toString());
    //System.out.println("Overall quality of the suggested day: " + suggestion.getQuality().toString());
    for (TimeSuggestion timeSuggestion : suggestion.getTimeSuggestions()) {
    System.out.println("Suggested time: " + timeSuggestion.getMeetingTime().toString());
    // Output additonal properties.
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    I am getting output like,
    Calendar event : Busy
    Start time: Tue Mar 03 10:00:00 GMT+05:30 2015
    End time: Tue Mar 03 17:00:00 GMT+05:30 2015
    Calendar event : Busy
    Start time: Wed Mar 04 12:00:00 GMT+05:30 2015
    End time: Wed Mar 04 13:00:00 GMT+05:30 2015
    Calendar event : Busy
    Start time: Wed Mar 04 13:00:00 GMT+05:30 2015
    End time: Wed Mar 04 18:30:00 GMT+05:30 2015
    Suggested day: Tue Mar 03 00:00:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 17:00:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 17:30:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 18:00:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 18:30:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 19:00:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 19:30:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 20:00:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 20:30:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 21:00:00 GMT+05:30 2015
    Suggested time: Tue Mar 03 21:30:00 GMT+05:30 2015
    Suggested day: Wed Mar 04 00:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 05:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 06:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 06:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 07:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 07:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 08:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 08:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 09:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 09:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 10:00:00 GMT+05:30 2015
    In the above output, for the corresponding date Mar 03, it is showing busy time correctly, but in the suggested time which is free , it is showing until 21.30 only, it need to showed until 23.30 as that also a suggested time which is free, Similarly, in
    next day ie. Mar 04, it shows busy time correctly, but suggested time which is free is shown until 10:00 am only, why it is not showing after 10 am. Please help me to solve this issue and how to proceed further to show the remaining free meeting time also.
    Thanks,
    Akshea.

    Hi Jason,
    Thanks for your response, your answer works ,i gave max. number of suggestions per day as 48, but i have a doubt,
    Suggested day: Wed Mar 04 00:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 11:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 18:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 19:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 19:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 20:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 20:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 21:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 21:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 22:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 22:30:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 23:00:00 GMT+05:30 2015
    Suggested time: Wed Mar 04 23:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 00:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 00:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 01:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 01:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 02:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 02:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 03:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 03:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 04:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 04:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 05:00:00 GMT+05:30 2015
    Suggested day: Thu Mar 05 00:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 05:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 06:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 06:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 07:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 07:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 08:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 10:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 10:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 11:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 11:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 12:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 12:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 13:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 13:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 14:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 14:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 15:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 15:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 16:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 16:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 17:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 17:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 18:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 18:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 19:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 19:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 20:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 20:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 21:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 21:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 22:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 22:30:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 23:00:00 GMT+05:30 2015
    Suggested time: Thu Mar 05 23:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 00:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 00:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 01:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 01:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 02:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 02:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 03:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 03:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 04:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 04:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 05:00:00 GMT+05:30 2015
    Suggested day: Fri Mar 06 00:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 05:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 06:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 06:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 07:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 09:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 09:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 10:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 10:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 11:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 11:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 12:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 12:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 13:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 13:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 14:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 14:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 15:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 15:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 16:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 16:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 17:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 17:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 18:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 18:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 19:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 19:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 20:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 20:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 21:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 21:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 22:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 22:30:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 23:00:00 GMT+05:30 2015
    Suggested time: Fri Mar 06 23:30:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 00:00:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 00:30:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 01:00:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 01:30:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 02:00:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 02:30:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 03:00:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 03:30:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 04:00:00 GMT+05:30 2015
    Suggested time: Sat Mar 07 04:30:00 GMT+05:30 2015
    This is my output,
    i gave start date from 04-Mar-2015 and end date 07-Mar-2015, so it shows me the meeting suggestion time from 04-Mar to 06-Mar till 23.30, that is fine, but for 07-Mar, it just shows first 10 meeting time only till 4.30 only, y so, on 07-Mar-2015 also it
    should give time till 23.30 . right.

  • Converting Date.toString() back to a Date object for compare

    I know this is beating a dead horse to death but I have wasted a whole day trying to get this to work. Here is the problem.
    I need to convert a Date().toString (format returned: Dec 19, 2006 3:39:58 PM EST) back to a Date object. What I am doing is writting this string a text file and then revisiting it to compare later to a current Date object to find the difference in the two stamps in milliseconds.
    J2SE 1.4.2 being used
    Date date = new Date();
    String newDateStr = log[1].trim(); // entry from log file
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date logDate = dateFormat.parse(newDateStr);
    // get difference between the two
    long timeSpan = date.getTime() - logDate.getTime();
    if(timeSpan > 60000){
        // TO DO
    }So should I look at a different approach at either:
    A) Storing the date/time stamp in the text file
    B) The conversion back to Date object is wrong
    Really appreciate any insight on this.
    Thanks
    JLW
    Message was edited by:
    jlwestsr

    Then my friend you are in the same status as Tim.:o)
    I don't know as much as him and I don't care to write
    an elaborate reply most of the time. :D
    Merry ChristmasSame to you.I don't pretend to know that much, but When I see something I do know, I tend to give examples.
    Most probably that is because at the present time I am in a situation where most of my time is spent waiting for a call from the customer, and the app I am supporting works so well that those calls are few and far between. Lucky for me, they pay me for sitting around and answering questions on a forum.
    At least it is a java forum, where I can justly claim that I am improving my knowledge of java.
    ~Tim

  • Convert String ("2008-Mar-25 08:33:36") to Date 2008-Mar-25 08:33:36

    I have a Date in String format. I need to convert it to Date in the same format. As in the subject the String is "2008-Mar-25 08:33:36" ; I need to convert it to a Date in the same format. Is there any way of doing it?
    I tried:
    DateFormat toSdf = new SimpleDateFormat("yyyy-mmm-dd hh:mm:ss");
    Date d = toSdf.parse("2008-Mar-25 08:33:36");// At this point it throws exception "java.text.ParseException: Unparseable date: "2008-Mar-25 08:33:36"
    I know similar threads have been posted. But im posting this again as none of the answers solved my problem. Inconvenience regretted.
    Thanks in Advance,
    Geet

    m is not the symbol for both months and minutes because that wouldn't make much sense would it?
    m is the symbol for minutes
    M is the symbol for months.
    You should also consult the API and make sure that you are using the right symbol for your hours values. That is a valid one but I have a feeling that your hour value might be 14 or the like sometimes which means you are using the wrong one there as well.

  • Conversion of one date format to another format..

    Hi all..
    Please help me out in this...
    I want to convert the following ...
    Fri May 25 17:49:34 2007 to[b] 2007-05-25 17:49:34
    Help me out of this ...
    Thanks in Advance .....

    Fri May 25 17:49:34 2007 to[b] 2007-05-25 17:49:34 If what you have already is of type java.util.Date, then just use formatting:
    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yourDate)If it's a String only, then you need to do conversion:
    SimpleDateFormat from = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
    SimpleDateFormat to = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    to.format(from.parse(yourString))

  • Convert DateTime

    How can I convert a Date-Time-String (yyyy-mm-dd hh:mm:ss) received from an AccessDB to a sequential integer?
    I receive the Date-Time-String in this format - for example:
    2004-12-30 07:30:29
    2004-12-31 09:42:19
    2005-01-01 10:53:34
    and I need the corresponding Integer counted by the system - for example:
    xxxxxx37
    xxxxxx38
    xxxxxx39 (what ever the actual value is)
    how can I get the System-Integer from these Strings ??

    You convert from String to Date with the java.text.SimpleDateFormat classes.
    String sDate = "2004-12-30 07:30:29"
    SImpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    Date date = sdf.parse(sDate);
    long dateInMillis = date.getTime();Note the above asuumes times are in 24 hour format.
    Check out the java API for java.text.SimpleDateFormat for full details on the format string.
    and I need the corresponding Integer counted by the system - for example:You mean the representation as a long - milliseconds since 1970?
    Once you have a Date object, you can get that easily.
    If you mean some other integer representation you will have to calculate it yourself.
    Cheers,
    evnafets

  • Oracle-java How to fetch data between two Timestamps

    hai...
    I am using a program where i have to get all the data entered into oracle db between two dates
    (The first date being manually inputted and the second one is inputdate-24hrs) . The code is as follows....
    Connection c = null;
    PreparedStatement pStmt = null;
    ResultSet rs = null;
    try
    //eg  String dt=14/03/2007, hr=03, min=27, ampm=am
         DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
         DateFormat outForm = new SimpleDateFormat("yyyy/MM/dd");
         Calendar cl = Calendar.getInstance();
         Date inDate = new Date();
         inDate = dateFormat.parse(dt);
         cl.setTimeInMillis(inDate.getTime());
         cl.add(Calendar.DAY_OF_MONTH, -1);
         String str1 = outForm.format(new Date(cl.getTimeInMillis()));
         String str2 = outForm.format(dateFormat.parse(dt));
         System.out.println("Changed date = "+str1);
         System.out.println("Original date = "+str2);
         String toStr = str2+" "+hr+":"+min+" "+ampm.toUpperCase();
         String fromStr = str1+" "+hr+":"+min+" "+ampm.toUpperCase();
         System.out.println("From date = "+fromStr);
         System.out.println("To date = "+toStr);
    // For example, if u r confused, From date = 2007/03/14 03:27 AM
    //                            To date = 2007/03/13 03:27 AM
         String sql = "SELECT TRANS_ID, TO_CHAR(CONCAT('Rs.',TRANS_VALUE)) AS TRANS_VALUE, " +
                   "TO_CHAR(TRANS_DATE,'DD/MM/YYYY HH:MM AM') AS TRANS_DATE, ACCOUNT_ID,  " +
                   "TO_CHAR(CREATED_DATE,'DD/MM/YYYY HH:MM AM') AS CREATED_DATE, CREATED_BY, " +
                   "INSTR_D_BANK_CD FROM TRANS_TB WHERE " +
                   "ACCOUNT_ID=? AND TO_CHAR(TRANS_DATE,'YYYY/MM/DD HH:MM AM') " +
                   "BETWEEN ? AND ? ;
         c=ds.getConnection();
         pStmt = c.prepareStatement(sql);
         pStmt.setString(1, accountId);
         pStmt.setString(2, fromStr);
         pStmt.setString(3, toStr);               
         rs = pStmt.executeQuery();     
    }The problem is that i am not getting results as expected
    Can anyone point out if there is something wrong in the logic or in the program....

    But how to make that string to the Timestamp object.
    I tried this way but failed !!!
    // Eg :fromStr = 2007/03/14 03:27 AM
    //       toStr= 2007/03/13 03:27 AM
         SimpleDateFormat sdfOutput = new SimpleDateFormat("yyyy/MM/dd hh:mm a");
         Date fromDate = sdfOutput.parse(fromStr);
         Date toDate = sdfOutput.parse(toStr);
    SELECT TRANS_ID, TO_CHAR(CONCAT('Rs.',TRANS_VALUE)) AS TRANS_VALUE, " +
                   "TO_CHAR(TRANS_DATE,'DD/MM/YYYY HH:MM AM') AS TRANS_DATE, ACCOUNT_ID,  " +
                   "TO_CHAR(CREATED_DATE,'DD/MM/YYYY HH:MM AM') AS CREATED_DATE, CREATED_BY, " +
                   "INSTR_D_BANK_CD FROM TRANS_TB WHERE " +
                   "ACCOUNT_ID=? AND TRANS_DATE BETWEEN ? AND ? ;
    //Eg TRANS_DATE = "11-MAR-07 12.30.59.729000000 PM"(Timestamp)
    c=ds.getConnection();
         pStmt = c.prepareStatement(sql);
         pStmt.setString(1, accountId);
         pStmt.setString(2, fromDate);
         pStmt.setString(3, toDate);               
         rs = pStmt.executeQuery();     
         I think there is problem in both String-Date conversion and in the query.....

  • How to covert from the following string to dateformat given below

    String stodate = "Tue Mar 22 09:13:36 CET 2005";
    Date d = new Date();          
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
      try
         d = sdf.parse(stodate);          
        System.out.println(d.toString());
       catch(ParseException e)
         System.out.println("Unable to parse: " + stodate);
      }I've got ParseException. How to solve the problem

    Didn't you ask this question only a couple of minutes ago?
    http://forum.java.sun.com/thread.jspa?threadID=609178

  • Format date with simple date format

    Hello
    I want to parse String to date. My method is
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    Then
    Date date = dateFormat.parse("2007-17-1100 11:11");
    It can be seen that the String "2007-17-1100" is invalid date. However, I donot know why it still can be parsed. Result is "Thu May 05 11:11:00 NZST 2011"
    Could you please explain. I want this one cannot be parsed.
    Many thanks
    shoa

    SimpleDateFormat dateFormat = new
    SimpleDateFormat("yyyy-MM-dd HH:mm");
    Then
    Date date = dateFormat.parse("2007-17-110011:11");
    >
    IIn my knowledge there is only 12 months in a Year.There are. But as long as the parsing is 'lenient' it knows how to handle month numbers greater than 12.
    @OP: Check out the setLenient() method. A setLenient(false) should make it work the way you want.

  • Can I change Calendar type to Date type?

    Hi Gentlemen,
    Here is the scenario.
    A user enters a date as string.
    I pass that string to a class named DateStamp
    where I get this string say [s]
    and parse it,then I create a date object.
    here is the code for it.
    public Date setThisDate(String s) {
    DateFormat format = new SimpleDateFormat("yyyy/mm/dd");
    Date d=null;
    try{
    d = format.parse(s);
    }catch(ParseException pe) {
    pe.printStackTrace();
    //Calendar date = new GregorianCalendar();
    //date.setTime(d);
    System.err.println(d.toString());
    return d;
    the error I got is,
    Unparseable date
    can some one guide me please.

    Your program is trying (and failing) to convert a String to a Date. So why do you keep asking how to convert a Calendar to a Date? That's not your problem. Your problem is that your SimpleDateFormat expects to be given a String containing a 4-digit year field, a slash (or dash), a 2-digit minute field, a slash (or dash), and a 2-digit day field. That doesn't make any sense, and that's why you get the error. It would work better if you specified a month field instead of a minute field:
    DateFormat format = new SimpleDateFormat("yyyy/MM/dd");

  • Time Zone issues EDT to PDT conversion. Really need help!

    Have a question regarding conversion from EDT to PDT time zones and on different Java versions...
    If you compile the program below and run it using JRE 1.6, 1.5 versus 1.4, 1.3 it gives different results. Maybe somebody has an answer:
    Here is the code:
    import java.text.*;
    import java.util.*;
    public class Moh {
            public static void main(String[] args) throws Exception {
                    SimpleDateFormat timestampFormatWithZone = new SimpleDateFormat("yyyy-MM-dd HH:mm z");
                    Date date = timestampFormatWithZone.parse("2007-06-06 14:00 EDT");
                    System.out.println(date.toString());
    }Copile it and run using these two options. The one with
    New York shall show you 2pm or 14:00 and when using the
    second one output changes:
    java -Duser.timezone=America/New_York Moh
    java -Duser.timezone=America/Los_Angeles Moh
    If you use JRE 1.6 or 1.5 second option will give you 12:00; if you
    use JRE 1.4 or JRE 1.3 it will show 11am or 11:00
    I think that 11am is correct! Is there any issues with newer JREs and timezone conversion. Or am I missing anything?
    Thank you so much for your help!

    Yes, there are issues. See the following from Sun Microsystems
    Sun(sm) Alert Notification
        * Sun Alert ID: 102836
        * Synopsis: Olson TZ Data (tzdata2005r or
    greater) Incompatibility Issues
        * Category: Availability
        * Product: Java 2 Platform, Standard Edition
        * BugIDs: 6466476, 6530336
        * Avoidance: Upgrade
        * State: Resolved
        * Date Released: 08-Mar-2007
        * Date Closed: 08-Mar-2007
        * Date Modified:
    1. Impact
    The introduction of Olson Timezone (TZ) data,
    version 2005r or greater, may break backward
    compatibility for the Eastern, Hawaiian, and
    Mountain time zones, under certain circumstances.
    This issue is also outlined in Sun BugIDs 6466476
    and 6530336, listed at:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6466476
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6530336
    Note: The Hawaiian TZ is only affected for
    historical data. Other American TZs such as PST and
    CST are not affected.
    2. Contributing Factors
    This issue can occur in the following releases for
    all platforms:
        * JDK and JRE v1.4.2_12 and above
        * JDK and JRE 5.0u8 and above
        * JDK and JRE 6 and above
    Notes:
       1. Releases below Java SE v1.4.x are not affected
    by this issue.
       2. The condition will also exist if you have run
    the "Time Zone Updater Tool" for v1.4.x+, but
    without the -bc flag.
    This condition will be apparent under one of the
    following two circumstances:
    A) The use of old 3-letter TZ IDs, limited to:
    "EST", "HST", "MST".
    Or:
    B) The parsing of date strings containing one of the
    following three TZ strings: "EDT", "HDT", or "MDT".
    3. Symptoms
    The symptoms/result of this condition will be that
    Daylight Saving Time (DST) will be calculated
    incorrectly.
    4. Relief/Workaround
    There is no workaround for this issue. Please see
    the Resolution section below.
    5. Resolution
    To resolve this issue (ie. to enable support for the
    backward compatible DST timezones), run the "Time
    Zone Updater Tool" for v1.4.x+ with the command line
    options:
        -f -bc
    Complete instructions for running the tool can be
    found at:
    http://java.sun.com/javase/tzupdater_README.html
    Note: If you have already run without the -bc flag,
    you will need to rerun with the -f -bc flag to
    correctly resolve the 3-letter TZ abbreviation issue.
    The -bc options will result in the deletion of the
    files:
        * JAVAHOME/jre/lib/zi/EST
        * JAVAHOME/jre/lib/zi/MST
        * JAVAHOME/jre/lib/zi/HST
    There are no known side effects to removing these files.
    Install Issues :
    In the unlikely event of unforeseen issues (e.g:
    such as power loss or I/O Error) restore the JRE
    Time Zone files to their original state by:
    A) following the instructions at
    http://java.sun.com/javase/tzupdater_README.html#remove
    Or:
    B) removing and then reinstalling the JRE or JDK.
    The update may now be re-applied by running the TZ
    Updater Tool (with the proper command line options)
    as listed above.
    For additional information on issues, products, and
    resources for DST changes, please also see:
    http://www.sun.com/dst
    This Sun Alert notification is being provided to you
    on an "AS IS" basis. This Sun Alert notification may
    contain information provided by third parties. The
    issues described in this Sun Alert notification may
    or may not impact your system(s). Sun makes no
    representations, warranties, or guarantees as to the
    information contained herein. ANY AND ALL
    WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT
    LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE
    HEREBY DISCLAIMED. BY ACCESSING THIS DOCUMENT YOU
    ACKNOWLEDGE THAT SUN SHALL IN NO EVENT BE LIABLE FOR
    ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, OR
    CONSEQUENTIAL DAMAGES THAT ARISE OUT OF YOUR USE OR
    FAILURE TO USE THE INFORMATION CONTAINED HEREIN.
    This Sun Alert notification contains Sun proprietary
    and confidential information. It is being provided
    to you pursuant to the provisions of your agreement
    to purchase services from Sun, or, if you do not
    have such an agreement, the Sun.com Terms of Use.
    This Sun Alert notification may only be used for the
    purposes contemplated by these agreements.
    Copyright 2000-2006 Sun Microsystems, Inc., 4150
    Network Circle, Santa Clara, CA 95054 U.S.A. All
    rights reserved.

  • Converting time between time zones

    I would like to convert a user input date between 2 time zones, for example between America/Chicago and Europe/Paris. So, when user enters 2005-02-10 13:00 America/Chicago, I need to calculate this time in Paris accounting for any daylight savings time. Could someone point me in the right direction to accomplish this. I believe, java.text.SimpleDateFormat can be used, but I can't get this to work. Thanks

    I would like to convert a user input date between 2
    time zones, for example between America/Chicago and
    Europe/Paris. So, when user enters 2005-02-10 13:00
    America/Chicago, I need to calculate this time in
    Paris accounting for any daylight savings time.
    Could someone point me in the right direction to
    o accomplish this. I believe,
    java.text.SimpleDateFormat can be used, but I can't
    get this to work. Thanks
         try
              String tz=TimeZone.getTimeZone("America/Chicago").getDisplayName();
              java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm z");
              Date d=sdf.parse("2005-02-10 13:00 "+tz);
              sdf.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
              System.out.println("Time in Paris: "+sdf.format(d));
         catch(Exception e){e.printStackTrace();}I dont know whether it is really working. Splitting of date -time and timezone has to be considered

  • I'm trying to parse date like: 2006-02-17T00:39:32.0000000+02:00

    I used code:
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZ");
    sdf.parse(2006-02-17T00:39:32.0000000+02:00);
    but I got:
    java.text.ParseException: Unparseable date: "2006-02-17T00:39:32.0000000+02:00"
    at java.text.DateFormat.parse(DateFormat.java:335)
    the thing is in last colon (between 02 and 00). Even if i use my sdf to formatany date i dot : '2006-02-17T00:39:32.0000000+0200' - without last colon.
    Another date parsers provide way to pasre this colon also (like using ZZ instead of Z and so...)
    Does java has such ability?

    Modification of sabre's hack to format the TZ data so that it matches SimpleDateFormat's format for General time zone GMT offset value.
    Date d = sdf.parse("2006-02-17T00:39:32.0000000+02:00".replaceAll("\\+","GMT+"));

  • Regex help... Need to improve regex skills

    Hi everyone
    I m new to java.
    currently I om working an a project that requires regex for parsing.
    I am able to parse the string but I feel that regex I wrote is not efficient.
    please help me.
    String: "Oct.8, 9, 15, 16, 22, 23, 29, 30Nov.5, 6, 12, 13, 19, 20, 26, 27"
    I want to parse Oct 8 and Nov 27 (start and end of the period)
    This is the regex that i wrote.
    regex: "([a-zA-Z]+)\..*,\s*(\d+)([a-zA-Z]+).*,\s*(\d+)"

    Found this on google, maybe it will help.
    try {
            // Some examples
            DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
            Date date = (Date)formatter.parse("01/29/02");
            formatter = new SimpleDateFormat("dd-MMM-yy");
            date = (Date)formatter.parse("29-Jan-02");
            // Parse a date and time; see also
            // e317 Parsing the Time Using a Custom Format
            formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
            date = (Date)formatter.parse("2002.01.29.08.36.33");
            formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
            date = (Date)formatter.parse("Tue, 29 Jan 2002 22:14:02 -0500");
        } catch (ParseException e) {
        }

Maybe you are looking for

  • MBP to HDMI looks fuzzy

    Why does the font on my 32-inch Samsung 1080p LCD TV look fuzzy when it is connected to my MBP via HDMI to Mini Display Port? It is only when it is connected to the MBP. When it is connected to my PS3 it is crystal clear. How can I fix this if at all

  • Internal Web Browser Issue

    We are working on our first digital publication and are having some issues with the internal browser. It appears to break web pages into strips see here: We have tried various sites using the same internal browser and they all break the same (on both

  • Calculation Based on Previous Day's Figure

    Hi all, This is a solution I implemented several years ago, which is now causing problems and must be rectified.  The intention was to compare a single field across two days and calculate the difference.  The only way I could figure out how to do tha

  • How to Use the Function Module 'BAPI_BUSPROCESSND_CHANGEMULTI'

    Dear Experts,          Can anyone Explain me how to Use the Function Module 'BAPI_BUSPROCESSND_CHANGEMULTI'.My Requirement is i want to change the Partners of the Service Order.It is Very Urgent Requirement Please Help me. Thanks & Regards, Ashok.

  • How to uninstall photoshop CS2

    I have tried everything to uninstall an old version of CS2. Is there anything that works?