?
Solved

Parsing date - URGENT

Posted on 2006-03-24
6
Medium Priority
?
296 Views
Last Modified: 2010-04-01
I am using this code:

    List okDates = new ArrayList() ;
    Calendar current = new GregorianCalendar();
    current.setTime( startDate ) ;
    while( current.getTime().compareTo( endDate ) <= 0 )
    {
        current.add( Calendar.DATE, 1 ) ;
       
        // CHECK IF THE current is a weekend...
        int dow = current.get( Calendar.DAY_OF_WEEK ) ;
        if( dow != Calendar.SATURDAY &&
            dow != Calendar.SUNDAY )
        {
                 // NOT SATURDAY, SUNDAY, or bank holiday...  Add it to the list of OK dates :-D
                okDates.add( current.getTime() ) ;
        }
    }

The dates i get in the okDates ArrayList are String and in the format "Fri Apr 07 00:00:00 BST 2006" and I need it in the format "2006-04-01" and it must be a date not string.

Help please
0
Comment
Question by:AndriesKeun
  • 4
6 Comments
 
LVL 10

Expert Comment

by:radarsh
ID: 16282807
Hi AndriesKeun,

You can just store dates in your okDates ArrayList. However when you want to display or whatever, you
can format it in the YYYY-MM-DD pattern.

 List okDates = new ArrayList() ;
    Calendar current = new GregorianCalendar();
    current.setTime( startDate ) ;
    while( current.getTime().compareTo( endDate ) <= 0 )
    {
        current.add( Calendar.DATE, 1 ) ;
       
        // CHECK IF THE current is a weekend...
        int dow = current.get( Calendar.DAY_OF_WEEK ) ;
        if( dow != Calendar.SATURDAY &&
            dow != Calendar.SUNDAY )
        {
                 // NOT SATURDAY, SUNDAY, or bank holiday...  Add it to the list of OK dates :-D
                okDates.add(new Date(current.getTime())) ;
        }
    }

To format, you can use a method like this:

private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

public String formatDate(Date date)
{
    return format.format(date);
}


________
radarsh
0
 
LVL 10

Expert Comment

by:radarsh
ID: 16282832
Remember one thing:

You CAN NOT have a date object stored in a certain pattern. i.e, date objects are
instances of java.util.Date (or any other) and if you format them, you'll get a
string (java.lang.String).

You can also do the other way round, parsing a string into a date object using the
parse method of SimpleDateFormat class.

________
radarsh
0
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 2000 total points
ID: 16289170
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:radarsh
ID: 16293027
My posts didn't help you at all??

Strange...
0
 

Author Comment

by:AndriesKeun
ID: 16293099
i tried them but still was getting weird stuff. eventually sorted it out myself using what shivaspk posted.  sorry mate.
0
 
LVL 10

Expert Comment

by:radarsh
ID: 16293324
That's alright! Never mind :-)

________
radarsh
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
With more and more companies allowing their employees to work remotely, it begs the question: What are some of the security risks involved with remote employees and what actions should we take to secure them?
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question