SimpleDateFormat: when day of month becomes day of week

I have a weird situation where the SimpleDateFormat class seems to interpret the "dd" mark as day of week instead of day of month when I use a certain pattern. The following code demonstrates the problem:
public class ByteTest {
    public static final String PATTERN = "mm HH dd MM F";
    // public static final String PATTERN = "dd MM yyyy";
    public static void main(String [] args) throws Exception {
        String str = "11 11 08 11 1";
        // String str = "24 11 2004";
        System.out.println(strToDate(str, PATTERN));
    public static Date strToDate(String date, String pattern) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        formatter.setLenient(false);
        return formatter.parse(date);
}The result (at least for me) is:
Exception in thread "main" java.text.ParseException: Unparseable date: "11 11 08 11 1"
at java.text.DateFormat.parse(DateFormat.java:335)
at ByteTest.strToDate(ByteTest.java:20)
at ByteTest.main(ByteTest.java:14)
When I change "dd" from 08 to 07, I get this:
Sat Nov 07 11:11:00 EET 1970
...and finally, when I change the pattern (done here by uncommenting the commented lines and commenting the ones above them), I get:
Wed Nov 24 00:00:00 EET 2004
So, as you can see, for some reason "dd" is interpreted as day of week number in the weirder pattern (which unfortunately we have to use in a pattern matching thing we are using). Any ideas?
When I comment the line with setLenient(false), it also works fine, but unfortunately we need to use that flag because otherwise users could input weird values for the various fields.
I tried adding Locale.UK to the parsing method, but that made no difference so clearly my locale (+02:00 GMT) is not at fault.
I also considered if the day might be out of range since using this pattern we get year 1970, but clocks start counting from 1.1.1970 right? So that doesn't seem a likely cause either. :-/
The markers for day of week in SimpleDateFormat are E and F; so I guess the question is, when does d become E or F...

I'm not sure I quite understand what the problem is... the reason why you can't parse that date is that it's invalid, Sunday November 8 on 1970 goes to the second week of the month, so day-of-week-in-month is 2, not 1.. so the string you should pass is "11 11 08 11 2"

Similar Messages

  • Sync Contacts Birthday :: month becomes day, vice-versa

    Hi,
    I'm using iPhone4 with iOS 4.3.3. I'm currently syncing my contacts with Google Contacts.
    Time zone is GMT +8:00 Singapore.
    What happens when I sync my contacts, the birthdays in Google will change the month to day & vice-versa.
    iPhone contact = 1 July 1980
    Google contact = 7 Jan 1980
    Anyway to solve this?
    Thanks.

    It is possible to sync to multiple machines for different content. However, the content must be on different tabs.
    example: You can sync calendars/contacts at work and music videos at home since they are on the Info and Music/Video tabs respectivly. You can not sync contacts at work and calendars at home since they are on the same tab (Info).
    Here is the step by step to set up multiple machine syncing:
    1. Select "Disable automatic syncing for all iPhones" under Edit / Preferences / iPhone in the iTunes menu.
    2. Uncheck "Automatically sync when this iPhone is connected" in the Summary tab of iTunes.
    3. Check "Only sync checked items" in the same tab.
    4. On the computer you want to sync contacts and calendar, check the corresponding boxes in the Info tab. UNCHECK everything else in the MUSIC, PHOTOS, PODCASTS and VIDEO tabs.
    5. Sync your iPhone with this computer FIRST.
    6. On your other computer, follow the same steps above (1, 2 and 3). Then, UNCHECK everything in the INFO tab, and check everything else on the other tabs.
    7. When you sync with this second computer, you may get a message that the iPhone has already been synced with another computer, and that the media library will be deleted. Fine. There should be NO media library on the iPhone since you unchecked all the media items on the first computer, right?
    8. Sync. Then you can sync on both computers and each will sync what is checked and not overwrite the rest.

  • Current date, first day of month, last day of month, current week, current

    Hi All,
    may be the question will sounds basic for your guys, I am connecting via MDX a cognos reportnet on a BW 3.0B..due to loads of limitations on filtering via MDX on 'business date/time functions' , I would need to create in the infoqueries that are my data sources, the following additionnal objects:
    - current date
    - first day of current month
    - last day of current month
    - current week
    - current year
    I do not want prefiltered infoqueiries but object with these single values so that from reportnet I can have something like: OCALDAY between 'first day of current month' and 'last day of curent month'
    Is there standard fonction for this under BW/BEX or if we need to developp functions has nayone some code examples.
    thanks a lot for your great input
    David

    Hi,
    In universe level if you want implement the requirede functions then you have to write custom sql and if you want to implement them in Reporting level then most of the functions are available to you. e.g. Quarter,Month, Year, Current Date....
    Cheers,
    Suresh A.

  • Convert days to months and days?

    Hi,
    I need to take a a numeric value like 280 (which is really the number of days) and convert it to the number of months and days (eg 9 months and 10 days). Is this possible with PowerShell?
    Thanks
    Adam

    $ht = @{Months=$days/30;Days=$days%30}
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    G
              ... rubbishell code ( from #2 ).
    I tested your rubbishell code, and got bad result:
    PS Q:\> $days=299 ; $ht = @{Months=$days/30;Days=$days%30} ; $ht
    Name                           Value                                                                                        
    Days                           29                                                                                           
    Months                         9,96666666666667                                                                             
    Do you really think 9,9666... is an integral number?
    No, it's not.
    If you wanna know the correct values, just look above at my last reply.
    I didn't realize you don't know how to truncate decimal.
    $ht = @{Months=[int](($days/30)-.5);Days=$days%30}
    But you did put together that convoluted mess to get the equivalent of a simple modulo operation, so that probably should have been a clue.
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    GREAT!
              ... rubbishell code ( from #2 ).
    I tested your rubbishell code ONCE MORE(!), and got bad result
    ONCE MORE(!):
    PS Q:\> $days=300 ; $ht = @{Months=[int](($days/30)-.5);Days=$days%30} ; $ht
    Name                           Value                                                                                        
    Days                           0                                                                                            
    Months                         10                                                                              
    Do you really think 10 is equal to 11?
    Don't you think the correct answer is 11?
    If you wanna know the correct values, just look above at my last reply.
    Give it up dude, you'd better copy and paste my PowerShell code.  :)
    No, I'm pretty sure 300 days at 30 days/month is 10 months.  
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Get Months and Days -- Problem with months_between

    Hi,
    For a report, I need to convert days as months and days for eg 370 days as 12 months 5 days.
    I tried below query
    with t as (
    select
    maturity_date - value_date tenor
    from account_master)
    select
    trunc(mod(months_between(trunc(sysdate,'YYYY')+ tenor,trunc(sysdate,'YYYY')),30)) month,
    (trunc(sysdate,'YYYY')+tenor)-add_months(trunc(sysdate,'YYYY'),trunc(months_between(trunc(sysdate,'YYYY')+ tenor,trunc(sysdate,'YYYY')))) "day"
    from t
    And i am getting output as
    MONTH day
    11 30
    23 30
    11 30
    1 5
    11 30
    11 30
    11 30
    0 6
    11 30
    for Number of days
    TENOR
    365
    730
    365
    36
    365
    365
    365
    6
    365
    As you can see for 365 days i am getting Months as 11 and days as 30
    and for 730 days i am getting months as 23 and days as 30.
    I want 365 days as 12 months and 0 days.
    I think it is months_between function that is creating this problem.
    Can anyone suggest another way of accomplishing this?
    Thanks and Regards
    Amit Trivedi

    2008 is a leap year! so it's 366 days long. therefore, 365 days is really only 11 months and 30 days (if you start counting from Jan 01, which is what you are doing).
    so the number of months and days between is dependent on the starting date (consider a range of 30 days starting on Jan 01, Feb 01 (leap year), Feb 01 (non-leap year) and Apr 01).
    so:
    with t as (
    select maturity_date - value_date tenor, value_date d1 from account_master
    select
    trunc(months_between(d1+ tenor,d1)) months,
    d1+tenor - add_months(d1,trunc(months_between(d1+ tenor,d1),30)) days
    from t
    or better yet:
    select
    trunc(months_between(maturity_date,value_date)) months,
    maturity_date - add_months(value_date,trunc(months_between(maturity_date,value_Date))) days
    from account_master
    /

  • Subtract   two dates to get   months and days

    I havew to subtract two dates and get the differnce ,
              Date issuedDate= myobj.getIssueDate();
              Date expirationDate=DateUtils.addMonths(issuedDate, 6);
              long timeDiff=expirationDate.getTime()-new Date().getTime();
              long daysRemaning=timeDiff/86400000;this is code I get the number of days between the issue date and todays date.now my client wants not just days but months and days , i need suggestions on how to get days and months between any two given dates

    I have read that it is best to use java.util.Calendar for almost any time related issue.
    With some switch statements and a for loop, I think the Calendar class could solve the problem.

  • How to get days and months when two dates are given

    Hi All,
    I have a requirement where I need to return the number of months and days between given dates.
    I dont need to take the year into account as the dates difference is always less than an year
    I have 28-jun-2012 and 31-jan-2013 as dates.
    I'm working on 10g
    when I do select months_between(:a,:b) from dual and provide those dates it gives me 7.09677
    I want it to give as 7 months and 9 days or what ever the exact days are.
    Your inputs are much appreciated

    BluShadow wrote:
    874719 wrote:
    Thanks a lot,BluShadow for your answer and would you mind giving it for the year as well like 0 years 7 months 3 days?Your original post said:
    I dont need to take the year into account as the dates difference is always less than an yearNow you've got the idea, why not have a go yourself first, and then if you're still not getting it, post what you've tried so we can help you.Oh... go on... I'm in a good mood today...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select date '2012-06-28' as start_date, date '2013-01-31' as end_date from dual union all
      2             select date '2012-02-29', date '2012-06-30' from dual union all
      3             select date '2010-02-28', date '2012-06-30' from dual union all
      4             select date '2012-02-29', date '2012-06-15' from dual
      5            )
      6  --
      7  select start_date, end_date
      8        ,months_between(end_date,start_date) as mnth_bet
      9        ,floor(months_between(end_date,start_date)/12) as yr
    10        ,floor(mod(months_between(end_date,start_date),12)) as mnth
    11        ,case when to_number(to_char(end_date,'DD')) >= to_number(to_char(start_date,'DD')) then
    12           to_number(to_char(end_date,'DD')) - to_number(to_char(start_date,'DD'))
    13         else
    14           (to_number(to_char(last_day(start_date),'DD'))-to_number(to_char(start_date,'DD')))+
    15           (to_number(to_char(end_date,'DD')))
    16         end as dys
    17* from t
    SQL> /
    START_DATE           END_DATE               MNTH_BET         YR       MNTH        DYS
    28-JUN-2012 00:00:00 31-JAN-2013 00:00:00 7.09677419          0          7          3
    29-FEB-2012 00:00:00 30-JUN-2012 00:00:00          4          0          4          1
    28-FEB-2010 00:00:00 30-JUN-2012 00:00:00         28          2          4          2
    29-FEB-2012 00:00:00 15-JUN-2012 00:00:00  3.5483871          0          3         15

  • When I try to synchronise my calendar it all goes wrong when I have recurring appointments which I enter on Outlook. These are in the format ' first Tuesday of each month' as I play Bridge with different partners on different days each month so it is NOT

    When I try to synchronise my calendar it all goes wrong when I have recurring appointments which I enter on Outlook. These are in the format ' first Tuesday of each month' as I play Bridge with different partners on different days each month so it is NOT every 4 weeks necessarily, it depends on the month.  These get lost on synchronisation or sometimes end up on a totally different day/date.  What can I do as it is very annoying.
    Also it altered some theatre dates where I had entered both date and name of play - the name of the play vanished when I synchronised not just on i-pad but it deleted the info from Outlook as well.

    Others have the same complaint.  iCal on the iPad can do recurring appointments, but not in the format you want (First Tuesday of every Month).  It will do the same DATE each month (e.g, the 25th of each month), but for now it does not do a particular DAY of each month.

  • Acrobat Pro XI transposes numbers for month and day in dates when saving optimized pdf to Excel spreadsheet.

    Using Adobe Acrobat Pro XI and Excel 14.3.8 on a mac. 
    Saved PDF as "optimized PDF" then "save as other" > spreadsheet > Microsoft Excel Workbook.
    Problem: numbers in some random dates are  transposed so that month and day are reversed.  No particular pattern to these errors.  Only fix we've found is to go through and manually check and correct the date errors - there are hundreds of these errors in the document so this is not a good solution.
    (Note: Excel columns with dates are specified as "date" fields. All dates are formatted as m/d/yy)
    Any ideas what's causing this problem problem and how to fix it? 
    Thanks in advance!

    [discussion moved to Creating, Editing & Exporting PDFs forum]

  • Dot is shown every day in month view, even with no events

    Hi All,
    With the latest iTunes update, my outlook calendar sync finally works, however, it has now decided to put a dot on every day in the month view, even on days I have no events. Outlook is still fine, so it does not appear that there is a corrupt event or anything.
    Has anyone else seen this and found a fix?
    Thanks in advance

    Here is the fix that worked for me. I hope it helps you out.
    Busy dots on every day of the month?
    The iPhone calendar month view shows a dot on every day you have an event scheduled. This allows you to know, at a glance, any "free" days you have with no appointment scheduled. There seems to be a bug with some type of all-day recurring events in Outlook that sync over improperly to the iPhone. This causes the iPhone to become "confused", and show the "busy dot" on every day of the month, whether the day has an event in it or not.
    In order to correct this problem, you will need to find the all-day recurring event or events (could be more than one) that are causing this. Without a search function, it takes a little bit of detective work, but it can be done.
    1. Browse backwards on your calendar until you find the first day of the month with no "busy dot" in it. This will help you identify when the problem started.
    2. Next, find the first instance of the problem - that is, find the first empty day that shows a "busy dot".
    3. Once you find that empty day, look at the days before to find an all-day recurring event (other types of events may cause this bug, but I only experienced it with all-day recurring events, such as birthdays, anniversaries, etc.)
    4. Edit the event - the start and end dates of the event should be, by definition, the same day. The bug apparently causes the event to sync over with the end date a day before the start date. This creates a situation that the iPhone calendar cannot handle properly, causing the dots to appear on every day from that point on forward. Fix the end date to be the same as the start date.
    5. This should fix the problem, at least until the next all-day recurring event. In my case, I had seven events I had to fix. Every time I fixed one, the empty days on the calendar would no longer show a "busy dot", but as I browsed forward, the problem appeared again. I noticed it appeared right after one of these faulty all-day recurring events. When I fixed the event, the days from that day on forward would correct themselves until the next faulty all-day recurring event. Once all seven all-day recurring events were fixed, the "busy dot" no longer appeared on any empty days.

  • Date Formatting - Day and Month Switching Places

    I am starting to get really frustrated with this problem; at first it was just a nuisance, but now when I actually want and need to do something important with Numbers it has become a major headache.
    When I first select a formatting and enter a date it works fine. I enter, e.g., "1 Aug 2009" and Numbers formats it "1 August, 2009" as per my formatting selection. However, when I go to change the formatting to, e.g., "day of week, day month, year" my "1 August 2009" suddenly becomes "Thursday, 8 January, 2009" - it switches the day and month values around! This happens no matter which format I choose, and no matter what I do - whether I enter the day first or month first, American or European - it always switches them around when I go to change the format. It's infuriating!
    Does anyone have any suggestions? What am I to do?

    Welcome to Apple Discussions
    I believe the problem is that you have US formats for dates. Select the cells/columns that you want your date format to apply to then click the cell format inspector (the 42 in a box icon) & choose Custom… from the cell format drop-down. You will be presented with a box that allows you to make your own format. Click & hold on any of the little "lozenges" in the input bar & move them around. You may need to add a space to get the proper result.

  • Highlighting multiple days in Month View?

    Hello everyone & Happy Friday All !!!
    I'm new to this forum, and VERY new to using ical -
    Here's my question:
    In my old method of using a calendar to do my schedule on my old PC -
    I'd make a spreadsheet in MS Excel that would show me monthly views that I could highlight days,
    weeks or entire months..... It's crude in comparison to ical, yet it IS effective for my needs......
    I am used to highlighting either a single day or a string of days in my "month" view,
    so... for example - let's say that Monday thru Thursday of next week I am going to be "out of the office in London - UK" -
    I would simply highlight the four days of next week - and instead of leaving those cells "white"
    like every other day in the month - I'd change those four cell's colored "fill" option from white to
    bright yellow - (or any other color that signifies a specific action or function - like "green" for vacation days, or "blue" for a sick day or surgery, etc....
    This way - that at a glance (literally) - I can tell that I'm "out of the office" on those days next week that are colored other than "white"..... NOTE: the ENTIRE CELL - Not Just the Day Title is colored......
    (I wish I could insert a visual example of what I am trying to describe here...)
    Is there a way of doing this same kind of function in ical - so that I can have an "at a glance" or
    "heads up display" that I can see quickly and know I'm committed on those days next week - or
    any week or group of days for that matter?
    This would help me tremendously of there is a way of doing this...... Otherwise - I'll be STUCK
    in the 90's using my improvised Excel Spreadsheet Calendar.....
    Thanks in advance for your help
    kevin

    Welcome to the discussions, azstoneconsulting.
    In iCal colours are tied to specific calendars, so make a vacation calendar and a sick calendar (you forecast your sickness? Cool) and an out of office calendar and set the colours to whatever colour suits. Then when you are going to be in London select the out of office calendar and set it to last the four days. It will show as a coloured bar across those days in month view.
    AK

  • How to calculate the number of days until your next birthday. Only using current month, day and birth month and day.

    I'm trying to calculate the number of days until your next birthday. Only using current month, day and birth month and day. I can get close but i'm way off. When i enter in the next day, the amount of days is supposed to be 364. This is where I am having problems. I know my code is way off. I just need some guidance please!
    Attachments:
    D5.7_1.vi ‏8 KB

    I just had a little fun with the Time Record...
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    D5.7_1_BD.png ‏19 KB

  • Changing the default event time to all-day in Month View?

    I updated to Mavericks today, and when I went to add an event to my Calendar, I discovered that all-day was not the default time.  In Mountain Lion, when going to add an event in Month View, it was automatically set to all-day, which is perfect because all of my events are all-day events.  Now, it's being set to 9:00 to 10:00, and I have to check the box to make it all-day.  I know that this isn't much work, but when I'm adding dozens of events it starts to get a little annoying.
    Calendar 7.0, OS X 10.9 (Mavericks).
    Any help would be greatly appreciated.

    npatelaz,
    I don't think that it is possible, even using Terminal. If you want to change your workflow, "all day" events can easily be created in the Day/Week view, but as you stated the Month view poses a problem.
    Calendar Help says:
    To make:
    An event that lasts all day:
    In Day or Week view, double-click in the “All-day” section at the top of the calendar.
    An existing event last all day:
    In Day, Week, or Month view, double-click the event, click the date, then select “All-day.”
    A multiday event:
    In Week view, drag from the start time to the end time. You can drag across multiple days.In Day or Month view, create an event. Then, enter the start and end dates and times.
    An all-day event into a multiday event:
    In Week view, drag the all-day event across multiple days.
    How to Change the Default Duration of New iCal Events - The Mac Observer was written over a year ago, but it may give you some other ideas.

  • ICal shows wrong month in day pane and in edit pane.

    I am running iCal 3.0.8 under OS X 10.5.8 on a MacPro Intel machine. In the Month view I suddenly saw the month-day-year of each event appearing in the day panel. I also saw this date in the edit panel for that event. The problem is that the MONTH in this displayed date was wrong. This is June. All of the dates in June said Jan (yes I had my glasses on). I had previously (but not recently) changed the date/time format in International to Custom, so I could show day, time, month, day date, year in the header bar of the screen. I think iCal is reading that format to get the full date but then is not getting it right. I discovered that if I opened International and changed the format spec to US (not US Computer) and then changed it back to Custom, part of the error in iCal disappeared. The date no longer appeared for each event in the day panel of month view. Just the time showed. However, the full date still showed in the Edit panel, and it was still wrong. All the dates say "Jan". If I change to July, the dates are still "Jan" in the Edit panel. They are still "Jan" if I am in Week View, etc.
    If I close iCal and then relaunch it, the error re-appears (if the date format in International is Custom), even if iCal was not showing the error in the day pane when I closed iCal.
    In sum:
    If the date format in International is US and I launch iCal, there is no date in the day pane of month view and the date display in the Edit pane is correct.
    If I change the date format in International to my Custom format, there is still no date in the day pane of month view BUT the date display in the Edit pane has the wrong month (Jan, no matter what the real month is).
    If the date format is Custom and I relaunch iCal, the date appears in the day pane of month view and is wrong in the Edit panel.
    I downloaded the calendar file to my laptop which is running iCal 4.0.4 under OS 10.6.7 and all displays were OK. BUT I had not messed with the date format on the laptop. So that only shows that there was nothing wrong with the calendar file as such. It is possible that if I changed the date format in International the iCal error would disappear and I could get it all OK on the desktop machine if I upgraded to 10.6. But I have a rule that says never upgrade to a new OS unless it is at least a year old. (That's been my unshakeable rule since 1983-4 :-) )
    Has anyone else seen this weird iCal problem?

    Hi,
    You can change this in System Preferences, Language & Text.
    Go to System Preferences > Language & Text > Formats tab and change where it says Custom to your location. Then re-open iCal.
    Best wishes
    John M

Maybe you are looking for

  • Create  a new domain in wlserver6.1

    Hi, I have weblogic 6.1 installed on my pc. i have created couple of ejbs and i run them from the mydomain domain they work fine. i want to create a new domain and make it up and running. i have got a documentation from bea which says details for cre

  • BT Premium mail & Broadband - at my wits end

    Converted my free @btinternet addresses to BT Premium mail last Sep.  Opted for BT Broadband in April. Have been trying ever since to get my Premium mail moved to the BT Broadband so I don't have to pay. Have been in touch many times with the BT Prem

  • Getting error in B2B for 5010 EDI

    Hi Guru's We have one requirement where one of our customer is using EDI version 5010( transaction 850 Inbound). The customer's trading partner uses his custom Version Number 5010VICS. So in order to setup the same in Oracle B2B ( version 10.1.2.3) w

  • Delete standby redo log from primary database

    Hi all, I'm trying to drop standby logfiles on primary database (other database that I'm configuring the DG). The members of the standby log groups don't exists on file system. Somebody have deleted these files. Its old configuration where the files

  • To set minimum size of flash panel

    I am developing a flash panel in PS CS5. I have tried many way to set minimum size of panel window, but they don't work. I have not idea how to do this now. I'm waiting for your HELP. Thank YOU!