Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

date format

Posted on 2004-10-10
1
Medium Priority
?
852 Views
Last Modified: 2011-09-20
I actually have 3 questions with date formats , can someon tell me how to do following

1) I need to display just current month and year on my JSP, like for this month display should be exactly "October, 2004. "  , also i have to display with date at an other place like "October, 10 2004"

2) I get Date as a string in format (MM/DD/YYYY)e.g 10/10/2004. I need to convert it again to just Month and Year format  like October, 2004.

3) Same as question 2, but in this case i get java.util.Date object instead of String.
I think these are easy but i have never worked with dates and formats..
Thanks in advance
0
Comment
Question by:soft_techy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

by:
MogalManic earned 200 total points
ID: 12272346
You will need to work with the SimpeDateFormat class.
  1) Convert today's date to Month, Year:
       <%
        Date today=new Date();
        SimpleDateFormat format=new SimpleDateFormat('MMMM, yyyy");
        %>
...
        <%-format.format(today);%>
  2) Convert a date string to a date Object (ignoring Day)
       <%
        String dateStr=request.getParameter("enteredDate");
        SimpleDateFormat format=new SimpleDateFormat('MM/xx/yyyy");
        Date date=format.parse(dateStr);
        %>
   3) Ignore day from Date object
       <%
        Date today=new Date();
        SimpleDateFormat format=new SimpleDateFormat('MMMM, yyyy");
        String dateStr format.format(today);    //Convert date to string
        today=format.parse(dateStr);             //Convert String to date
        %>
        OR
       <%
             Date today=new Date();
             Calendar dt=Calendar.newInstance();
             dt.set(Calendar.DAY, 1);   //Set the month to 1st of the month
             dt.clear(Calendar.HOURS);  //Remove the time
             dt.clear(Calendar.MINUTES);
             dt.clear(Calendar.SECONDS);
             dt.clear(Calendar.MILLISECONDS);
             today=dt.getTime();  //Today now is the first of the current month
      %>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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