SimpleDateFormat, exclude wrong dates

Is there a way to exclude incorrect dates with a SimpleDateFormat? I mean, say for instance that you want to enter 31st of June, 2009. That should produce an error, because that date is not possible. However, for some reason, that date is converted to the 1st of July.
What I can do is convert the text to a Date object, than convert it back to a String and compare it to the original value. If these are different, throw an error. However, I hope there's a better, more proper way of doing this. Any help would be appreciated :-).

I am unaware of a something that would automatically throw an error if that happened....
But, there are only 12 months, and most of them are either 30 or 31 days. (not much work)
Im not going to write all the code for you, You need to figure most of it out...but you could do something like:
if (  (day > 31) && (month == Jan || month ==Mar ||...))
else if ((day > 30) .... ))
...just dont forget about Feburary, and leap years ars every 4 years (it may be more complicated i dont remember):
bool leapyear = false;
if (years % 4 == 0)
  leapyear = true;

Similar Messages

  • SimpleDateFormat parses wrong date successfully (lenient = false). Why?

    Hi
    I've got a problem validating date by SimpleDateFormat. Format "yyyy" successfully parses string like "2009-78" into date 01.01.2009. Can you please help me with it?
    Here is my code:
    SimpleDateFormat format = new SimpleDateFormat("yyyy");
    format.setLenient(false);
    String dateStr = "2009-78";
    Date date;
    try {
        date = format.parse(dateStr);
    } catch (ParseException e) {
        date = null;
        e.printStackTrace();
    System.out.println(String.format("String '%s' parsed to date %s", dateStr, date));Output:
    String '2009-78' parsed to date Thu Jan 01 00:00:00 MSK 2009I need an exception to be thrown in such situation. How can I check where the string represents a correct date?
    Thanks for your help.
    Evgeny
    Edited by: su.eug on Apr 13, 2009 12:56 AM

    Read the comments in the API:
    [http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html#parse(java.lang.String)|http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html#parse(java.lang.String)]
    You could try the other overload of parse, if you want to test whether the whole String was used:
    [http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#parse(java.lang.String, java.text.ParsePosition)|http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html#parse(java.lang.String,%20java.text.ParsePosition)]
    (Sorry--the second link doesn't go to the right place. There is a version of "parse" with two parameters, which you can use to determine if the whole String was used.)

  • SimpleDateFormat gives the wrong date

    Hi
    I'm retreiving a java.sql.Date, and using a SimpleDateFormat("dd.MM.yyyy") to format it. For some reason, some of my users (located in other countries) end up with the wrong dates (it's an applet)and others don't. Any similar experiences/thoughts?

    Thanks for the info....I'm using 1.3, so that's unlikely to be it.
    I narrowed it down to a timezone problem difference problem between my applet and the server. Does anyone know how I can get an applet to behave like it's in a different timezone. Is there a single place I can set it (like maybe a System.setTimezone or something?). I don't want to go around messing with my Locales in every single Date or Calendar object I use. I just need my applets to think they're running in the same timezone as the server. Any similar experiences/quick fixes?

  • Downloads with Safari show wrong date

    Hi, this is my first post and I'm stumped.
    When I download a file (i.e. PDF) via Safari on either my Imac or Macbook (4.03 and 4.02) both running Leopard 10.5.7 it shows up in my downloads folder with the wrong date: wrong year, month, and day.
    When I download the same file with Firefox the download date is correct.
    Does anyone have any suggestions to remedy this annoying problem? Thanks.

    Ok. I just downloaded a PDF via Safari that shows the creation date as: 23/12/08 1:10 AM.
    Same file downloaded via Firefox shows date correctly: today at 9:16 PM.
    The date from Safari has been all over the map... 03, 07, 00 etc. all different.
    Message was edited by: i-Mack

  • Wrong Dates in Sent Folder

    After doing a clean install of 10.5 and importing all of my mail messages from my .mac account, I noticed that many of the messages in my sent folder had the wrong date. Apparently they were marked with the date on which I first synchronized my 10.5 Mail with my .mac account. I've since tried to rebuild that folder, and when I do that, those problematic messages show up as sent "Today" at the time I rebuilt, even though many of them are nearly a year old. Any suggestions as to what might be causing this? I've read several threads regarding problems with the sent folder, but none with this specific date problem.
    Thanks.
    One more thing...
    All sent message show up with the correct date when I access the sent folder online through .mac.
    Message was edited by: James Casey1

    I tried several experiments and noticed that if you move the messages in "sent messages" with wrong dates to another folder (for example to the "inbox") then they get back to their correct date.
    Apparently rebuilding mail boxes at this point doesn't fix anything, as if you move the messages into "sent messages" again then the date gets wrong again.
    Funny enough, when the message is back into "sent messages" and appears there with the wrong date, if you make a text search FROM THE INBOX on all folders in the search results these messages will appear as located in "sent messages" with THE RIGHT DATE!!! Doing the same search when you are in "sent messages" will show the message with the wrong date!!!
    So I am now sure there is BIG BUG in Mail about this.
    So unless Apple fix this, I guess the only way is to put all the messages from your "sent messages" with wrong dates in a folder where they appear with the correct date, save or export your "sent messages" folder messages, delete entirely your "sent messages" folder, and reload all you "sent messages" again.
    However I have no safe procedure for this and it won't prevent the bug to reoccur later on...

  • IPhoto imports photos with wrong dates even if the dates are fine on the camera

    Hi!
    When I import photos with iPhoto, sometimes it imports them with wrong dates, even the dates are fine on the camera. It puts dates such as 2032. Does anyone know how can I fix that. As far as I know there is no way to change dates of the photos.
    Thanks!

    well that is very confusing since if the date is correct on the camera it will be correct in iPhoto
    and as to
    As far as I know there is no way to change dates of the photos.
    Try looking through your iPhto menus - two commands - adjust time and date and batch change time and date - asjust is used to correct incorrect dates like a comera setting -   Batch change for missing dates like with scans
    LN

  • Report returns wrong data when run on server

    Hi,
    I'm runing CRS XI R2 on Windows Server 2003 SP2.  When I refresh a report in the Crystal Reports XI Designer, I'm getting correct data.  But when I schedule the report to run on the server it returns wrong data.  The data is different from what I see when I refresh it from the designer.  In the report I have running totals set up to count customers that meet a certain criteria.  The report is very large.  It take almost 2 hours to refresh.
    I was wondering what is causing the difference in running total data between refreshing it on the designer and running it on the server.  Is it returning wrong data b/c of it not reading all the records?  Should I be making any changes to the server settings?  I saw that under pageserver, there are options for  setting the 'Minutes Before an Idle Report Job is Closed' and 'Database Records To Read When Previewing Or Refreshing a Report".  Do either of those have anything to do with the report returning incorrect data when being scheduled to run on the server?
    Thanks,
    Kim

    Hi Xuandao,
    You would need to Use Cell Binding and Trigger concept to accomplish this.
    Its simple, however, you would have to work on a trial and error basis to understand this concept as implementing the same is subject to your dashboard and WEBI Design.
    Open you LiveOffice.
    Insert your WEBI, Now, go to Object Properties of your WEBI, select the second tab that says Prompt, Here, it lists the prompts that you have for your WEBI. This would also enlist your BEx variables as well. Select this BEx variable and click on the button that says Prompt at the bottom of this window. Here, select choose Excel Data Range and click on the cell select button on the right (small button that lets you choose what cell you want to bind this prompt to), Now select a free cell that would not be even populated later on when you run the dashboard say A1 (remember the value that you select). Click on OK and again OK. The WEBI Refreshes and you can see all the prompt values at the cell A1. These are all the possible values stored for your BEx prompt variables (these values are fetched from BW system dynamically).
    Now, save this LiveOffice, Go to you dashboard. Connect your dashboard to your Live office. Go to Data-> connections-> Now, select the WEBI and in the right hand pane  go to Usage tab, here, Click on Trigger cell button on the right hand side and select A1 in you LiveOffice.
    It should work fine.
    Let me know.
    Rgds,
    Sreekul Nair

  • How can I get my @mac email to work? when I try to reset password, i cannot access email for this and the security tells me I have wrong date of birth

    Have used bilmac@mac email address for years last couple of weeks am getting message icloud needs password which it then rejects, when I try to reset password,they want email to verify i cannot access email and the security question is D. O B. it tells me I have wrong date of birth. so I am stumped, any ideas bilmac

    COME ON PEOPLE. (WHY ARE THE LETTERS SO BIG HERE?) I AM VERY OLD AND JUST LIKE THINGS TO STAY THE SAME. I DID NOT, DO NOT, WANT ICLOUD TO DO ANYTHING I HAVE NOT USED IT AT ALL YET IT HAS MANAGED TO MESS UP MY EMAIL ADDRESS WHICH I HAVE BEEN USING FOR YEARS, IT ASKS FOR PASSWORD THEN REJECTS AND WHEN I TRY TO RESET WITH APPLE ID THEY ASK FOR SECURITY AS I CANNOT ACCESS THE EMAIL ADDRESS THEY HAVE FOR ME BECAUSE ICLOUD ASKS FOR PASSWORD, THEN APPLE TELL ME I DONT KNOW MY OWN DATE OF BIRTH, VERY CONFUSING

  • Ical birthday calendar wrong dates

    Hello,
    I have an issue with iCal regarding the birthday calendar.
    It works pretty fine syncing with address book, but it ads the birthday obviously twice. The birthday itself and the day before the birthday. When refering the URL in iCal it directs me to the Contact card of the person and there is only the correct date.
    Why does iCal do that? And more important, how can I solve that problem and remove all the wrong dates? Because it is anoying to have birthday reminders for people twice. It also looks pretty dumm in the notification center of Mountain Lion. With two birthdays of the same person in a row. Mostly it has one year difference as well, so the same person turns lets say 29 the one day and 30 the other.
    Any ideas?

    Thanks for your help.
    I've just checked forward into 2014 and I see that it doesn't re-occur  then.
    Strange, it's just one person and it's only happening in 2013. Their birthday is on 31st March and there's and entry for 31st Mar and 1st April.
    I'm not going to worry about it anymore.

  • How to find out Which LineItem is having the wrong data

    Hi All,
    This is Idoc--File scenario
    Iam sending the Idoc from R/3 and it may have several Line items and related data.
    If One line item data is wrong also the Idoc will be errored Out in MONI,for this i used UDF in mapping  to through the Exceptions. So i have to goto WE05 in R/3 and i have to check each and every line item for wrong data and then i will repost it.
    the thing is how can i find out the Particular line item is caused for this Error.
    REgards

    Hi Sarvesh,
    No, in MONI it will not take us to the correct Lineitem which is having the wrong data.
    That is only the problem here.
    Any Views.........
    Regards

  • Calendar List view shows entries under the wrong date

    I just upgraded to iOS4 and finding that my calendar entries are appearing under the wrong date in the calendar list view when I am viewing two calendars.
    - List view is ok when viewing 1 calendar
    - Day and Month views are ok at all times (ie: viewing single or multiple calendars)
    - I have 2 Exchange accounts
    - Calendar entries are appearing in the correct order, but under the incorrect date heading.
    - When I intially added the Exchange accounts the calendar list view was fine at first (I could see both calendars correctly in list view) but after a short time later it became screwed up.
    Anyone else experience this?

    Same problem here since my upgrade to iOS4 - but I only noticed today.
    I have 3 calendars set up:
    Gmail (Exchange)
    UK Holidays (iCal)
    Birthdays
    The exchange calendar is always wrong but the other two are correct when my exchange calendar is switched off.
    It has mucked up my scheduling a bit for the next month. I only became suspicious when I noticed the Scottish Bank Holiday Monday at the beginning of August was showing on FRIDAY, 30th of July!

  • Wrong date: January -- October

    As a replacement for my old Eudora, I tried Mail app today. With my Intel Mini it works great. However, with my G4 Mini, new mails are dated January 2007 instead of October 2007. Messages are even recognized as from 'Today' while having January 2007 as the date. Because dates are OK on my other Mini, I guess this is not a server issue.
    View > Message > Raw Source shows the right date: Mon, 8 Oct 2007 11:38:09 +0200.

    1. Mail shows email from the future: received mail dated 27/10/2007. In Entourage the same mail is dated 27/01/2007. All other months are OK. Remember we use European date settings (dd/mm/yyyy). Therefore I guesed something goes wrong with the dateformat.
    2. When I exported the mail form Entourage to .eml on my desktop the date in the mailheader showed 27/01/2007. So I figured the error occurs in Mail App. the same thing happened when I moved the mail directiy to my Imap folder in dotmac from inside Entrourage.
    3. However looking in the source information of the mail it showed not the date of the mail header but an entirely different date. Therefore I concluded that the root of the error in not Mail App or Dotmac (allthough those could also be wrong...)
    4. For exporting my mail from Outlook2007 to Entourage I used the tool O2M from Light Machines. Checking their help produced the following information:
    "Entourage shows the wrong date for imported emails
    This is an Entourage bug, but we created a workaround for it in O2M 1.02. If you're not sure which version of O2M you have, run O2M and check the version number in the program's title bar. If the version number doesn't say 1.02 or higher, download a new copy of O2M, install it over your old copy, and export your Outlook mail again — the date problem will be fixed when you import your newly exported mail into Entourage." and additionally:
    "Mail shows the wrong date for imported emails
    It may be your email has non-US date formats to begin with. If this is the case, you may want to change your date settings on both your Windows and Macintosh machines to US/English before performing your conversion and importing operations.
    O2M converts US/English dates to the standard MBOX format. If the date in the header is formatted differently from the US/English version of Outlook, the dates may not convert well. We don't currently support date formats other than US/English."
    5. Conclusion: I have to live with this as my XP machine is already used elsewhere.

  • Calendar app icon is displaying the wrong date

    For some reason on my iPhone's homescreen the icon for the Calendar app has today started displaying the wrong date.
    It should show today's date, Monday 6th but instead it reads Sunday 5th.
    What confuses me is that the phone does know the date is Monday 6th as the lock screen shows it correctly and also when I actually load the Calendar app it starts on the right date. Also, when I load the multi task bar the Calendar app icon there is correct. See the attached photo, which shows the Calendar app on the home screen (faded, middle left) displaying yesterdays date Sunday 5th, while the app icon in the multi task bar is correct, Monday 6th.
    Syncing the calendar with my iMac does not correct the error. Equally, turning the phone off and on again has not sorted it.
    Does anyone have any idea what might be causing the fault? And more importantly how to correct it?
    Thanks.

    Thanks for the suggestion DaVBMan, sadly it didn't work. The only thing that did work was to wait until midnight and it corrected itself. In the mind of the phone it lived a whole day twice and then skipped one completely in order to get back on track. Very odd and also I have since discovered it has happened to a few of my friends too.
    It's not happened again so I have no idea what so ever what caused it. Fingers crossed it never recurs.

  • In Responses, Can I export the data in a pdf form excluding null data?

    In Responses, Can I export the data in a pdf form excluding null data?

    Let me make sure I understand the request...  There is a feature in the Response table to "Save Response as PDF Form" and you'd like to do this excluding the null data (unanswered questions).  If that is correct it is not supported, the "Save Response as PDF form" will save a PDF that is the entire form filled out as the user filled it.
    Thanks,
    Josh

  • Time Machine restored wrong data

    OK - the history here is the previous Macbook was replaced because of system problems, including many files with FUTURE dates (eg. 2037). Apple store agreed after repeated issues, they would replace the machine. We did a final time machine/capsule backup before taking it in.
    Got the new Macbook and ran the Migration assistant to restore all data from the time capsule.
    The data was not correct, and I suspect it was something to do with the future dates.
    I can open the sparse bundle backup file and see the correct backup information, but I have no option when I open Time Machine to pick ANY previous backups.
    This all started with Macbook problem, and I'm really thinking they should figure this out - but assuming they wont, I'm looking for suggestions on how to safely get the 'real' information recovered from Time Capsule.
    Thanks
    Dan
    PS - OS X Lion on both systems - Macbook Pro 15" i7, 750GB

    JDHam wrote:
    Got the new Macbook and ran the Migration assistant to restore all data from the time capsule.
    The data was not correct, and I suspect it was something to do with the future dates.
    Possibly.  Migration Assistant uses the most recent backup, so if the dates were wrong, you may have gotten the wrong data.
    You should be able to see the other backups -- but you may need to start from a different user account (Migration Assistant creates a new account, and the transferred account may not have permission to the backups.  See Problems after using Migration Assistant for an explanation.
    A better option may be to do a full system restore, from a different backup.  See Time Machine - Frequently Asked Question #14 for detailed instructions.  You'll want to pick a backup from before the dates went wrong.

Maybe you are looking for

  • Error in creation of sample database during installation of Oracle8

    I am trying to install Oracle8 for Intel Solaris8. Near the end of installation - running database configuration assitant, the creation of the sample database failed by an alert: ORA-03114: not connected to ORACLE I also tried to run database configu

  • Any way to change blob size -- do I need to?

    I'm tinkering around with remote blob storage in my dev environment -- doing a lot of different options to see how it really works.  One thing I noticed is that when I dragged a file to a document library and it got stored under my filestream filenam

  • Tried to connect to TV, display died

    I hope someone can help me with this one! I have been having some issues lately connecting my ibook to a tv ... kinda of had to fidget with the video plug to get it to work right. It would be almost all the way plugged in but not quite and then it wo

  • Connecting the I-touch to home network

    Hello Everyone. I'm having trouble connect my wife's i-touch to the house router which is a Linksys 2.4ghz Model wrt54G. The i-touch is version 3.1.3 (7e18) model MC086LL the wireless is enable but there are about 9 different channels (speeds) that I

  • Capture Problem!! Footage has Disappeared!!!!

    Hi there, I realize this isn't directly to do with adobe (however I'm using CS4), but I know that there are some really smart people on this forum, and I'm hoping a fellow adobe user will help me out of this disastrous situation I find myself in. The