WEEK_OF_MONTH parsing in SimpleDateFormat

Hello,
I am trying to use the WEEK_OF_MONTH (capital W) in SimpleDateFormat. I want to be able to do both parse() and format() of in the format "yyMMWW". I also want to use false lenient in order to have strict control.
I have seen that the first week every month (WEEK_OF_MONTH == 1) can not be parsed properly. Below is an example program demonstrating the issue.
The program tries 100 dates from Jan 1 2006 and onwards. It converts to the yyMMWW format (which always goes fine). I also try to convert back from the yyMMWW format (using parse() method) and see that it fails on some dates.
I get an parse exception like this:
060204 -> 060201 -> java.text.ParseException: Unparseable date: "060201"
060205 -> 060201 -> java.text.ParseException: Unparseable date: "060201"
060206 -> 060202 -> 060206
060207 -> 060202 -> 060206
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class SimpleDateFormatIssue {
     public static void main(String[] args) throws ParseException {
          GregorianCalendar cal = new GregorianCalendar();
          cal.setFirstDayOfWeek(Calendar.MONDAY);
          cal.setLenient(false); //Strict checkin, significant for the issue
          //System.out.println(cal.getMinimalDaysInFirstWeek()); //doesnt matter what
          SimpleDateFormat fYYMMDD = new SimpleDateFormat("yyMMdd");
          fYYMMDD.setCalendar(cal);
          SimpleDateFormat fYYMMWW = new SimpleDateFormat("yyMMWW");
          fYYMMWW.setCalendar(cal);
          Date d = fYYMMDD.parse("060101");
          for (int i = 0; i < 100; i++) {
               String outputYYMMWW = fYYMMWW.format(d);
               Date parsedYYMMWW = null;
               Exception exc = null;
               try {
                    parsedYYMMWW = fYYMMWW.parse(outputYYMMWW);
               } catch (ParseException e) {
                    exc = e;
               System.out.println(fYYMMDD.format(d) + " -> " + outputYYMMWW + " -> " + (parsedYYMMWW != null ? fYYMMDD.format(parsedYYMMWW) : exc));
               d = getDayAfter(cal,d);
     public static Date getDayAfter(Calendar cal, Date date) {
          cal.setTime(date);
          cal.add(Calendar.DAY_OF_MONTH,1);
          Date dayAfter = cal.getTime();
          return dayAfter;
So I wonder, am I doing SimpleDateFormat abuse when I want to parse a yyMMWW formated string?
Or perhaps I have a bug in my program... :)
I saw some bugs in bug parade about SimpleDateFormat and WEEK_IN_MONTH but they all appears to be fixed in Java 5 which I am using:
java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
Thank you in advance for any pointers.
/Anders

The ones that fail are the ones before the first Monday of the month (since you set Monday as the first day of the week). So, I guess saying you are in the first week "060201" can't be translated back to a Monday in February.
Not sure what to do about it, though. (I didn't look what, if anything, any bugs said about it.)

Similar Messages

  • Strange result of SimpleDateFormat.parse()

    Hi,
    I'm having trouble with the parse data function as it does not return the correct hour.
    Here is what I'm doing:
    Date nullDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse("1900-01-01T00:00:00-0000");I would now expect nullDate to be Mon Jan 01 00:00:00 CET 1900
    But instead, it is Mon Jan 01 00:09:21 CET 1900
    Personally I cannot think of a reason why the time is not 0.
    Any ideas?

    I don't see the problem you see. What version of Java on what OS and in what time zone?
    P.S. I would certainly set the time zone for the parser i.e.
           SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            parser.setTimeZone(TimeZone.getTimeZone("UTC"));
            Date nullDate = parser.parse("1900-01-01T00:00:00-0000");
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
            System.out.println(formatter.format(nullDate));On my Ubuntu 10.04 using JDK 1.6.0_20 in London (currently GMT) time zone I get
    1900-01-01 00:00:00 GMT

  • 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.

  • Parsing TimeZone using simpleDateFormat

    Hi,
    I have a String: "14/03/2007 21:07:07 Europe/London" which i want to convert into java.sql.Date.
    Any ideas whats the simplest approach?
    I have tried using the SimpleDateFormat( "dd/MM/yyyy hh:mm:ss z" ) but then it fails to parse.
    Seems I am missing something simple here :)
    Ta,

    This smells like a bug in the parse method.
    If you have a date + time + valid timezone string, then the method should be able to create a Date - otherwise, how does one get the correct Date?
    Running the program below resulted in this output and unparseable error (changing the timezone to "PST" runs ok.)
    ***timezone dump = sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,
    lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,
    startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
    ***timezone id = America/Los_Angeles
    ***data to be parsed = 14/03/2007 21:07:07 America/Los_Angeles
    java.text.ParseException: Unparseable date: "14/03/2007 21:07:07 America/Los_Angeles"
    at java.text.DateFormat.parse(DateFormat.java:337)
    at Time.main(Time.java:22)
    The parse method in DataFormat calls an abstract method which is implemented in SimpleDateFormat. That code is convoluted (!), but certainly appears to me to be trying to match against timezone strings like "America/Los_Angeles".
    Other opinions?
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.TimeZone;
    public class Time
        public static void main(String[] args)
            TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
            // The preceeding line is copied from the TimeZone API example code
            System.out.println("***timezone dump = " + tz);
            System.out.println("***timezone id = " + tz.getID());
            String parseMe = "14/03/2007 21:07:07 " + tz.getID();
            System.out.println("***data to be parsed = " + parseMe);
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss zzzz" );
            try
                Date date = sdf.parse(parseMe);
            catch (ParseException ex)
                ex.printStackTrace();
    }

  • Need to parse Japanese Full Date Format

    Hi,
    Locale japanLocale = Locale.JAPAN;
    SimpleDateFormat fullDateFormat = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, japanLocale);
    String dateValue = 2010'?'09'?'12'?' 1'?'15'?'45'?'GMT // Here Japanese character will come instead of ?
    DateFormat initialDateFormat = new SimpleDateFormat(fullPattern, japanLocale);
    Date date = initialDateFormat.parse(dateValue);
    String formattedDate = fullDateFormat.format(date);
    This throws Exception java.text.ParseException: Unparseable date: "2010'?'09'?'12'?' 1'?'15'
    ?'45'?'GMT"
    If you send some good suggestions, it will be appreciable.
    Thanks in Advance
    Suresh

    Japanese full pattern is:
    "yyyy'&#24180;'M'&#26376;'d'&#26085;' (EEEE)
    H'&#26178;'mm'&#20998;'ss'&#31186;' z"
    I need to parse this string.
    OK:
    String pattern = "yyyy'&#24180;'M'&#26376;'d'&#26085;' (EEEE) H'&#26178;'mm'&#20998;'ss'&#31186;' z";
    String date = "2004&#24180;8&#26376;12&#26085; (&#26408;&#26332;&#26085;) 13&#26178;56&#20998;01&#31186; EEST";
    SimpleDateFormat parser = new SimpleDateFormat(pattern, Locale.JAPAN);
    Date d = parser.parse(date);
    System.out.println(d); // prints Thu Aug 12 13:56:01 EEST 2004
    Note that for the sake of portability the two first lines should be written asString pattern = "yyyy'\u5e74'M'\u6708'd'\u65e5' (EEEE) H'\u6642'mm'\u5206'ss'\u79d2' z";
    String date = "2004\u5e748\u670812\u65e5 (\u6728\u66dc\u65e5) 13\u664256\u520601\u79d2 EEST";This is to make it possible to compile your code on a platform that doesn't support Japanese script.
    Can i have your Yahoo / AOL ID?What makes you think I have one? :)

  • String to SimpleDateFormat Conversion

    I have a String in YYYYMMDDHHMMSS format. I want to convert it into SimpleDateFormat.
    Please share your ideas.......
    Thanks in advance

    Hi
    If you know the format of input string, you can try below code...
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class DateFormatTest
         public static void main(String [] args) throws ParseException
              String inputDate = "20100514101001";
              SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
              Date myDate = df.parse(inputDate);
              SimpleDateFormat dfNext = new SimpleDateFormat("dd/MM/yyyy hh mm ss");
              System.out.println("Formatted Date: " + dfNext.format(myDate));
    }

  • UrGEnt HELP ... PARSING DATE

    hello,,
    I have this string:
    String dateTime = "7/10/1996 4:50:00 PM";
    I need to convert it to Date ( Parsing) to Date Object...
    I am using this Formatting :
    SimpleDateFormat parse = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
    because I need the am/pm info also...
    but I get different format
    Wed Jul 10 16:50:00 GMT 1996
    which is wrong .. I dont know why I get it .. it should be a date object with value: "7/10/1996 4:50:00 PM";
    any help ??

    gold wrote:
    Hi !!
    Please make use of the below code,
    String dateTime = "7/10/1996 4:50:00 PM";
              SimpleDateFormat parse = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
              Date date = new Date(dateTime);
              String formatedDate = parse.format(date);
              System.out.println(formatedDate);I can't help myself I'm going to have to comment.
    To basharf,
    Please do NOT use that example at least not this part of it.
    String dateTime = "7/10/1996 4:50:00 PM";
    Date date = new Date(dateTime);The Date constructor that takes a String is deprecated. It was deprecated sometime in the previous century. Why anybody ever thought that was a good idea is beyond me. But that's a rant for another day. As I think you realize, SimpleDateFormat.parse is a better way to create a Date from a formatted String.

  • Error : while running OTL page.

    Hi All,
    I am getting the below mentioned error when I clicked the 'YES' button in the Warning page which comes after clicking the Save Button in Create Timecard ( OTL)  page using the customised controller code.
    Kindly help me to understand what cause this error..
    I am attaching the code below.
    public class XXTmecardsListCO extends TimecardsListCO
      public XXTmecardsListCO()
    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
         if (oapagecontext.getParameter("SaveYes") !=null )
           oapagecontext.putParameter("Action","TimecardSaveForLater");
           oapagecontext.putSessionValue("TimecardMode","TIMECARD-SAVED-FOR-LATER");
           super.processRequest(oapagecontext, oawebbean);
         else
            super.processRequest(oapagecontext, oawebbean);
      public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
        OAApplicationModule oaapplicationmodule = oapagecontext.getApplicationModule(oawebbean);
        String userName = Long.toString(GlobalUtilities.getEmployeeID(oaapplicationmodule, oapagecontext));
       String empEmailAddress=null;
       String supEmailAddress=null;
       String  iD = null;
       String supID=null;
       String Name=null;
       String supName=null;
      String finalStartTime=null;
      String finalStopTime=null;
      String finalStartTime1=null;
      String finalStopTime1=null;
      DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");//2015/06/15
           try
           Date date1 = (Date)formatter.parse(startTime);
           Date date2 = (Date)formatter.parse(stopTime);
           SimpleDateFormat newFormat = new SimpleDateFormat("dd/MM/yyyy");
           finalStartTime = newFormat.format(date1);
           finalStopTime = newFormat.format(date2);
           System.out.println("Start Date : " + finalStartTime);
           System.out.println("Stop Date : " + finalStopTime);
           SimpleDateFormat newFormat1 = new SimpleDateFormat("dd-MMM-yyyy");
           finalStartTime1 = newFormat1.format(date1);
           finalStopTime1 = newFormat1.format(date2);
           System.out.println("Start Date1 : " + finalStartTime1);
           System.out.println("Stop Date1 : " + finalStopTime1);
           catch (Exception ex )
              System.out.println(ex);
      if(oapagecontext.getParameter("Hxccuitcsaveforlater")!=null)
      oracle.apps.fnd.framework.server.OAApplicationModuleImpl amImpl = (oracle.apps.fnd.framework.server.OAApplicationModuleImpl) oaapplicationmodule;
      OAViewDef viewdef=(OAViewDef)oaapplicationmodule.getOADBTransaction().createViewDef();
      viewdef.setSql("SELECT Approval_status FROM APPS.HXC_TIMECARD_SUMMARY WHERE RESOURCE_ID = NVL(:1,RESOURCE_ID) AND start_time =  NVL(to_date(:2,'dd/mm/yyyy'),start_time)");
      oracle.jbo.ViewObject OAViewObject=amImpl.createViewObject("StatusVO",viewdef);
      OAViewObject oaviewobject = (OAViewObject)oaapplicationmodule.findViewObject("StatusVO"); 
    if(oaviewobject!=null)
    System.out.println("Vo is not null : ");
      oaviewobject.setWhereClauseParam(0,userName);
      oaviewobject.setWhereClauseParam(1,finalStartTime);
    oaviewobject.executeQuery();
    oracle.jbo.Row row1 = oaviewobject.first();
    System.out.println("Fetched Count: "+ oaviewobject.getFetchedRowCount());
    System.out.println("Row Count: "+ oaviewobject.getRowCount());
    if(row1 !=null)
    String status = row1.getAttribute(0).toString();
    oaviewobject.remove();
    if(status.equals("APPROVED") || status.equals("SUBMITTED"))
        System.out.println ("Inside Save ..query not null and status Approve/Submitted");
        OAException descMesg = new OAException("GEPSFND", "XX_CUSTOM_OTL_SAVE_CHANGE");
        OADialogPage dialogPage = new OADialogPage(OAException.WARNING, descMesg, null, "", "");
        dialogPage.setOkButtonToPost(true);
        dialogPage.setNoButtonToPost(true);
        dialogPage.setPostToCallingPage(true);
        dialogPage.setOkButtonItemName("SaveYes");
        dialogPage.setNoButtonItemName("SaveNo");
        oapagecontext.redirectToDialogPage(dialogPage);
    else
        System.out.println ("Inside Save botton not null and not Approved/Submitted");
        super.processFormRequest(oapagecontext, oawebbean);
      else
      oaviewobject.remove();
       System.out.println ("Query returned 0 rows");
       super.processFormRequest(oapagecontext, oawebbean);
        else if (oapagecontext.getParameter("SaveYes") != null)
            System.out.println ("Inside dialogue Yes");
            oapagecontext.putParameter("Action","Timecard");
            oapagecontext.putSessionValue("TimecardMode","TIMECARD");
            oapagecontext.putParameter("Hxccuitcsaveforlater","");
            oapagecontext.putParameter("_FORM_SUBMIT_BUTTON","Hxccuitcsaveforlater");
            super.processFormRequest(oapagecontext, oawebbean);
    else if(oapagecontext.getParameter("SaveNo") != null)
    super.processFormRequest(oapagecontext, oawebbean);
    else
    super.processFormRequest(oapagecontext, oawebbean);
    Please look into the code and let me know whats wrong in it.
    Thanks,
    Sukanya

    Hi Johny,
    Thanks for your suggestion!
    As per the requirement ,on click of YES button in Warning page, the Save confirmation message should be displayed along with Timecard entries.
    For that I  have written
    oapagecontext.putParameter("Action","TimecardSaveForLater"); 
           oapagecontext.putSessionValue("TimecardMode","TIMECARD-SAVED-FOR-LATER"); 
           super.processRequest(oapagecontext, oawebbean); 
    This part is working fine.
    if I modify the code according to your suggestion, what can I write for the YES button trigger ?
    Can you please provide your valuable suggestion on this ?
    Thanks,
    Sukanya

  • How to convert a String("yyyy-mm-dd") to the same but in Date format ?

    Hi,
    can anyone plz tell me how to convert a String to a date format.I'm using MSACCESS database.I want to store this string in the database.So i need to convert it to a date format since the table is designed such a way with date/time type for date field.I used SimpleDateFormat ,but i can't able to convert.The code is given below:
    coding:
    public String dateconvertion(String strDate)
    try
    SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdfSource.parse(strDate);
    SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd ");
    strDate = sdfDestination.format(date);
    catch(ParseException pe)
    System.out.println("Parse Exception : " + pe);
    return(strDate);
    }

    i used prepared statement even now i am getting error like this.....
    i have included the prepared statement package also...
    my coding:
    ResultSet rsdatetemp = null;
    PreparedStatement ps = null;
    String query ="select distinct itemcode from sales where bill date between ? and ?";
    ps = precon.prepareStatement(query);
    ps.setDate(1,d1);//d1 and d2 are in date format
    ps.setDate(2,d2);
    rsdatetemp = ps.executeQuery();
    error :
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(1,d1);
    symbol : method setDate(int,java.util.Date)
    location: interface java.sql.PreparedStatement
    ps.setDate(2,d2);

  • Days of week

    Hi...
    How can I know the date of next DAY_OF_WEEK.
    For example:
    today is wednesday, April 14, 2004.
    I need know the date of next SATURDAY.
    Thank you

    Hi...
    I continuous with the problems...
    Look at this code:
      public static boolean fechaCompare(String dateTest, int dias) {
        //Get todays date          //
    //    String dateToday = new SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
        Calendar calHoy = Calendar.getInstance();
        Calendar calTest = Calendar.getInstance();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        try {
          calHoy.setTime(df.parse(new SimpleDateFormat("yyyy-MM-dd").format(new java.
              util.Date())));
          calTest.setTime(df.parse(dateTest));
        catch (ParseException pe) {
          System.err.print("Could not parse date: " + dateTest + "\r\n");
          return false;
        calTest.add(Calendar.DATE, dias);
        java.util.Date dateToday = calHoy.getTime();
        java.util.Date dateNewTest = calTest.getTime();
        System.out.println(calTest.getTime() + " >= " + calHoy.getTime()+" -> "+((calHoy.get(Calendar.DAY_OF_WEEK)<= calTest.get(Calendar.DAY_OF_WEEK)) && dateToday.after(dateNewTest)));
    //if dateTest is less then today date, return true, else return false;
    //    if (dateToday.after(dateNewTest) || dateToday == dateNewTest) {
        if ((calHoy.get(Calendar.DAY_OF_WEEK)>= calTest.get(Calendar.DAY_OF_WEEK)) && dateToday.after(dateNewTest)) {
          return true;
        return false;
      }and this are some println result:
    Mon Jun 09 00:00:00 EDT 2003 >= Wed Apr 14 00:00:00 EDT 2004 -> false
    Mon Jun 09 00:00:00 EDT 2003 >= Wed Apr 14 00:00:00 EDT 2004 -> false
    Thu Sep 16 00:00:00 EDT 1999 >= Wed Apr 14 00:00:00 EDT 2004 -> true

  • How to get the hour:minuts:seconds using java

    I have table xydata
    here i get the gsTime like this 2010-04-21 10:58:40
    the above time i want to get only 10:58:40
    how to write the java for this
    please help me
    Thanks in Advance

    Problem of this sort cry out for using regular expressions. It is what they were invented for. If the OP wanted the whole date parsed into a java.util.Date then it would be a different matter and SimpleDateFormat would be the way to go but extracting part of a string is what regular expressions are best at.
    In this case, even a regular expression approach is far too complex. Which of the following do you consider the most appropriate ?
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Sabre20100508
        public static void main(String[] args) throws Exception
            String[] lines =
                "2010-04-21 11:01:35",
                "2010-04-21 11:01:58",
                "2010-04-21 11:02:21",
                "2010-04-21 11:02:42",
                "2010-04-21 11:03:28",
                "2010-04-21 11:03:51"
                Pattern p = Pattern.compile("(?<= )\\d{2}:\\d{2}:\\d{2}");
                System.out.println("Method 1 :-");
                for (String line : lines)
                    Matcher m = p.matcher(line);
                    if (m.find())
                        System.out.printf("    [%s]\n", m.group());
                Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} (\\d{2}:\\d{2}:\\d{2})");
                System.out.println("Method 2 :-");
                for (String line : lines)
                    Matcher m = p.matcher(line);
                    if (m.matches())
                        System.out.printf("    [%s]\n", m.group(1));
                System.out.println("Method 3 :-");
                for (String line : lines)
                    String[] splitLIne = line.split(" ", 2);
                    System.out.printf("    [%s]\n", splitLIne[1]);
                System.out.println("Method 4 :-");
                for (String line : lines)
                    int index = line.lastIndexOf(" ");
                    System.out.printf("    [%s]\n", line.substring(index + 1));
                System.out.println("Method 5 :-");
                SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
                for (String line : lines)
                    Date date = parser.parse(line);
                    System.out.printf("    [%s]\n", formatter.format(date));
                System.out.println("Method 6 :-");
                for (String line : lines)
                    System.out.printf("    [%s]\n", line.replaceAll("[^ ]* ", ""));
    }My vote goes to method 4!

  • How to compare the current system time with two timing?

    want to get the current system time and compare with the two different timing example startwindow time as 2:00:00AM and endWindowTime as 6:00:00AM. if my current system time falls between these window i have to execute my rest of the code.
    my below code works for fine for JAVA 1.6 version when i do the same code with JAVA 1.4 i am getting different date and time
    String starTime=(String) NightlyvendorStatus[0].getPropertyValue("startTime");
      String endTime=(String) NightlyvendorStatus[0].getPropertyValue("endTime");
      Date windowStarttime = new SimpleDateFormat("HH:mm:ss").parse(starTime);
      Date windowEndtime = new SimpleDateFormat("HH:mm:ss").parse(endTime);
      Date systemdate = new Date();
      SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
      String systemTime=parser.format(systemdate);
      Date currentTime = new SimpleDateFormat("HH:mm:ss").parse(systemTime);
      if (currentTime.after(windowStarttime) && currentTime.before(windowEndtime)){
    --- rest logic here---}
    the output from JAVA 1.4 IS Thu Jan 01 02:00:00 GMT 1970 Thu Jan 01 06:00:00 GMT 1970 Thu Jan 01 03:23:00 GMT 1970
    HOW TO DO this logic..

    Hi,
    You can try converting dates into timestamp and compare just like as comparing two integers variables.
    Regards,
    Anshul

  • Java Embedding Weird XML Node Error

    Ok, I am going crazy. I have a java embedding node that takes a date string in, changes it to a different format and creates another date that contains the current time. if I run this in java to code run ok and there are no issues. At the end of the java I print out the string and they are exactly what I want. The thing that is going on is when I set the 2 string BPEL variables in the java embedding, when I try to reference them the 2nd time,I get a weird node object error. I get through the first pass ok. when I try to reference Test1 or Test2 on the 2nd pass I get the error below. Its like when I set the variable currentDB2UpdateDate and currentDB2CurrTimeDate it does something to them. Instead of setting it to just the string it seems to set it to some kind of object.
    I have 3 steps here. Assign -> Java Embedding -> Assign.
    Assign 1 => Initialize 2 String variables to X.
    <code>
    <assign name="Assign_2">
    <copy>
    <from expression="string('X')"/>
    <to variable="currentDB2UpdateDate"/>
    </copy>
    <copy>
    <from expression="string('X')"/>
    <to variable="currentDB2CurrTimeDate"/>
    </copy>
    </assign>
    </code>
    Java Embedding =>
    <code>
    String currentFileDate = (String)getVariableData("currentFileDate");
    String currentDate = "";
    try
    SimpleDateFormat sdfSource = new SimpleDateFormat("MM/dd/yyyy");
    Date date = sdfSource.parse(currentFileDate);
    SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    currentFileDate = sdfDestination.format(date);
    catch(ParseException pe)
    System.out.println("Parse Exception : " + pe);
    try
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    currentDate = sdf.format(cal.getTime());
    catch(Exception pe)
    System.out.println("Parse Exception : " + pe);
    System.out.println("currentFileDate : " + currentFileDate.toString());
    System.out.println("currentDate : " + currentDate.toString());
    setVariableData("currentDB2UpdateDate",currentFileDate);
    setVariableData("currentDB2CurrTimeDate",currentDate);
    </code>
    Assign 3 =>
    <code>
    <assign name="Assign_1">
    <copy>
    <from variable="currentDB2UpdateDate"/>
    <to variable="Test1"/>
    </copy>
    <copy>
    <from variable="currentDB2CurrTimeDate"/>
    <to variable="Test2"/>
    </copy>
    </assign>
    </code>
    <code>
    <bpelFault><faultType>0</faultType><selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"><part name="summary"><summary>Invalid to part type.
    When performing the assign operation, the to node 2010-07-17 12:00:00 is invalid.
    The node named in the error message was either null or an empty node set, and it was not an instance of org.w3c.Element.
    Verify the node value at line number 819 is not null and is an instance of org.w3c.Element.
    </summary></part></selectionFailure></bpelFault>
    </code>
    The 2nd pass to this throws the following error when trying to set Test1 and Test2 again... Its like it is setting the variable to an object and not just the string. I tried using toString() in the setVariable too and it didn't work. I don't get it.
    Edited by: 806312 on Dec 1, 2010 8:13 AM
    Edited by: 806312 on Dec 1, 2010 8:26 AM

    I am also facing a similar issue.There is selection failure in assignment to local variable of BPEL .
    PFB the logs :
    parts: {{
    summary=&amp;lt;summary&amp;gt;Invalid to part type.
    When performing the assign operation, the to node false is invalid.
    The node named in the error message was either null or an empty node set, and it was not an instance of org.w3c.Element.
    Verify the node value at line number 3577 is not null and is an instance of org.w3c.Element.
    &amp;lt;/summary&amp;gt;}
    Here is the code:
    <copy>
    <from expression="xpath20:add-dayTimeDuration-to-dateTime($calculatednpexectime,'P200YT')"/>
    <to variable="calculatednpexectime"/>
    </copy>
    It seems as if Oracle is not accepting the date format .
    Is there some issue with local variables of new version of BPEL ??

  • Problem in date converting into dbFormat()

    Respected Experts,
    I am get the current date into String vaiable and from this string variable i want to convert into dateformat.
    For converting to date format i write the .java file. It converts date correctly into format "dd/mm/yyyy" but i want date format into "dd/mm/yyyy HH:MM.pm/am", so what change should i do in my following progaram.
    import java.text.SimpleDateFormat;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.util.Date;
    public class UtilityFunction
         public static String toUserFormatDate(Date dt)throws ParseException
         SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");
         String str=sdf.format(dt);
         return str;
         public static java.sql.Date toDbFormatDate(String sdt)throws ParseException
         SimpleDateFormat sdf=new SimpleDateFormat("dd/MM/yyyy");
         Date d=sdf.parse(sdt);
         SimpleDateFormat nsdf=new SimpleDateFormat("dd-MM-yyyy");
         String str=nsdf.format(d);
         Date nd=nsdf.parse(str);
         java.sql.Date rdate= new java.sql.Date(nd.getTime());
         return rdate;
         public static void main(String args[])throws ParseException
              SimpleDateFormat df=new SimpleDateFormat("dd-MM-yyyy");
              Date d2 =df.parse("08-09-1984");
              System.out.println("Date converted to User interface form");
              System.out.println("Database Date"+"08-09-1984");
              String p=toUserFormatDate(d2);
              System.out.println("Converted date"+p);
              java.sql.Date r=toDbFormatDate("12/12/2009");
              System.out.println("Date converted to database form");
              System.out.println("User Interface Date"+"12/12/2009");
              System.out.println("Converted date"+r);
    }

    After 22 posts on the forums, I'd have expected you to have learnt how to use the code tags by now (click on 'CODE' when posting)
    And while you get points for posting an SSCCE, you've left too much fluff in there. I don't know what method you want to discuss.
    And if you've reached this far with the SimpleDateFormat, what kept you from reading the rest of patterns available? It's all the same thing, you just needed to make it dd/MM/yyyy hh:mm a
    Do note that with your code, you're creating a date from a string that's missing the time, so you'll only get 12:00 AM all the time, for the above pattern. And also, you'd be using hh and not HH since putting AM/PM with 24 hour clock time is plain dumb.

  • European Style Date Converter - mm/dd/yyyy to dd.mm.yy

    Hi, I am trying to write a program that reads a string for a date in the format mm/dd/yyyy and display it in the typical European format of dd.mm.yy
    For example if the input is 03/13/2004 I'd like the output to appear as 13.03.04. Also I'd like it to use the JOptionPane for I/O.
    Thanks very much!

    alex_t88 wrote:
    Hi, I am trying to write a program that reads a string for a date in the format mm/dd/yyyy and display it in the typical European format of dd.mm.yy SimpleDateFormat parse = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
    I'll leave the rest for you. Check out parse and format methods, and read the javadocs.

Maybe you are looking for

  • Quicktime Installation Failed: Error Code : -3

    Whenever I try to install Quicktime 7.03 and iTunes for Windows, I always get this error. iTunes appears to install, but iTunes won't run. I really need to get quicktime installed. Someone PLEASE help me.

  • When will my icloud folder reflect memory upgrade? I am trying to move files from google drive folder to icloud.

    My icloud folder does not reflect storage upgrade.  I only had 25GB on my google drive and I have 500GB on my icloud but cannot move these files over. Whats up?

  • FTP Receiver without directory change

    Hello, we have to upload data to an FTP server which does not allow directory changes. Problem is that the directory field in the FTP receiver communication channel is mandatory so we get an error message. Is there any workaround for this? Thank you.

  • Help for Help

    Hi I remember i have used a SAP Help wich shows a window when we can write a word and it shows the documentation help for that word. This is like help window showed when we press F1 in some code line in ABAP program for search help for some ABAP comm

  • Ovi Suite does not recognise special MP3 files

    My Ovi Suite does not import some of my MP3 files, even though they have proper ID3 tags (there are even albums where some files are recognised and others not, although I can see no difference in the "quality" of the tags). If I directly choose one o