You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Galbreath <ma...@qat.com> on 2003/05/23 01:57:04 UTC

[OT] General Java Question: java.util.Calendar

Okay, I've been working for 12 hours straight and started boozing (Jim Beam
) about 2 hours ago (isn't working at home great?), but I can't seem to 

1. Get a String "Apr 12, 2003" into a Calendar object;
2. Test the day of the week the date represents.

Clues?  :-)

tia,
Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] General Java Question: java.util.Calendar

Posted by Mark Galbreath <ma...@qat.com>.
Thanks Jason and Josh!  You guys are spot-on!

Mark

-----Original Message-----
From: Jason Lea [mailto:jason@kumachan.net.nz] 
Sent: Thursday, May 22, 2003 8:35 PM
To: Struts Users Mailing List
Subject: Re: [OT] General Java Question: java.util.Calendar


You can use java.text.SimpleDateFormat to parse your string into a Date 
object.  Then create a Calendar object and use calendar.setTime(your 
date object).


Then use calendar.get(Calendar.DAY_OF_WEEK) which should return 
Calendar.SATURDAY if it is a Saturday.

--jason


Mark Galbreath wrote:
> I mean, why didn't Gosling ( or whomever architected the Calendar 
> class ) realize that it MIGHT be nice if the class could take a String 
> date and convert it to a Calendar object????
> 
> Mark
> 
> -----Original Message-----
> From: Mark Galbreath [mailto:mark_galbreath@qat.com]
> Sent: Thursday, May 22, 2003 8:20 PM
> To: 'Struts Users Mailing List'
> Subject: RE: [OT] General Java Question: java.util.Calendar
> 
> 
> JSP <html:form> <html:text> User enters a date and I need to verify 
> that it lands on a Saturday.  This is so simple to do client-side, but 
> I'm having a hellava time getting validation on the server.
> 
> Mark
> 
> -----Original Message-----
> From: Hunter Hillegas [mailto:lists@lastonepicked.com]
> Sent: Thursday, May 22, 2003 8:02 PM
> To: Struts List
> Subject: Re: [OT] General Java Question: java.util.Calendar
> 
> 
> Where are you inputting from?
> 
> I know that some of the JSTL tags make it easy to get a date in, and 
> the format you described shouldn't be a prob.
> 
> 
> 
>>From: "Mark Galbreath" <ma...@qat.com>
>>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>Date: Thu, 22 May 2003 19:57:04 -0400
>>To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
>>Subject: [OT] General Java Question: java.util.Calendar
>>
>>Okay, I've been working for 12 hours straight and started boozing (Jim 
>>Beam
>>) about 2 hours ago (isn't working at home great?), but I can't seem 
>>to
>>
>>1. Get a String "Apr 12, 2003" into a Calendar object;
>>2. Test the day of the week the date represents.
>>
>>Clues?  :-)
>>
>>tia,
>>Mark


-- 
Jason Lea


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] General Java Question: java.util.Calendar

Posted by Jason Lea <ja...@kumachan.net.nz>.
You can use java.text.SimpleDateFormat to parse your string into a Date 
object.  Then create a Calendar object and use calendar.setTime(your 
date object).


Then use calendar.get(Calendar.DAY_OF_WEEK) which should return 
Calendar.SATURDAY if it is a Saturday.

--jason


Mark Galbreath wrote:
> I mean, why didn't Gosling ( or whomever architected the Calendar class )
> realize that it MIGHT be nice if the class could take a String date and
> convert it to a Calendar object????
> 
> Mark
> 
> -----Original Message-----
> From: Mark Galbreath [mailto:mark_galbreath@qat.com] 
> Sent: Thursday, May 22, 2003 8:20 PM
> To: 'Struts Users Mailing List'
> Subject: RE: [OT] General Java Question: java.util.Calendar
> 
> 
> JSP <html:form> <html:text> User enters a date and I need to verify that it
> lands on a Saturday.  This is so simple to do client-side, but I'm having a
> hellava time getting validation on the server.
> 
> Mark
> 
> -----Original Message-----
> From: Hunter Hillegas [mailto:lists@lastonepicked.com] 
> Sent: Thursday, May 22, 2003 8:02 PM
> To: Struts List
> Subject: Re: [OT] General Java Question: java.util.Calendar
> 
> 
> Where are you inputting from?
> 
> I know that some of the JSTL tags make it easy to get a date in, and the
> format you described shouldn't be a prob.
> 
> 
> 
>>From: "Mark Galbreath" <ma...@qat.com>
>>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>Date: Thu, 22 May 2003 19:57:04 -0400
>>To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
>>Subject: [OT] General Java Question: java.util.Calendar
>>
>>Okay, I've been working for 12 hours straight and started boozing (Jim
>>Beam
>>) about 2 hours ago (isn't working at home great?), but I can't seem to
>>
>>1. Get a String "Apr 12, 2003" into a Calendar object;
>>2. Test the day of the week the date represents.
>>
>>Clues?  :-)
>>
>>tia,
>>Mark


-- 
Jason Lea


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] General Java Question: java.util.Calendar

Posted by Josh McCulloch <jj...@netscape.net>.
Try this:

import java.text.*;
import java.util.*;

public class Test
{
  public static void main(String[] args)
      throws Exception
  {
    String str = "Apr 12, 2003";

    if(isOnSaturday(toDate(str)))
    {
      System.out.println("Saturday");
    }
    else
    {
      System.out.println("Nope.");
    }
  }

  public static Date toDate(String str) throws ParseException
  {
    SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy");
    return sdf.parse(str);
  }

  public static boolean isOnSaturday(Date date)
  {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);

    return (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY);
  }
}

HTH
- Josh

mark_galbreath@qat.com wrote:

>I mean, why didn't Gosling ( or whomever architected the Calendar class )
>realize that it MIGHT be nice if the class could take a String date and
>convert it to a Calendar object????
>
>Mark
>
>-----Original Message-----
>From: Mark Galbreath [mailto:mark_galbreath@qat.com] 
>Sent: Thursday, May 22, 2003 8:20 PM
>To: 'Struts Users Mailing List'
>Subject: RE: [OT] General Java Question: java.util.Calendar
>
>
>JSP <html:form> <html:text> User enters a date and I need to verify that it
>lands on a Saturday.  This is so simple to do client-side, but I'm having a
>hellava time getting validation on the server.
>
>Mark
>
>-----Original Message-----
>From: Hunter Hillegas [mailto:lists@lastonepicked.com] 
>Sent: Thursday, May 22, 2003 8:02 PM
>To: Struts List
>Subject: Re: [OT] General Java Question: java.util.Calendar
>
>
>Where are you inputting from?
>
>I know that some of the JSTL tags make it easy to get a date in, and the
>format you described shouldn't be a prob.
>
>
>  
>
>>From: "Mark Galbreath" <ma...@qat.com>
>>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>>Date: Thu, 22 May 2003 19:57:04 -0400
>>To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
>>Subject: [OT] General Java Question: java.util.Calendar
>>
>>Okay, I've been working for 12 hours straight and started boozing (Jim
>>Beam
>>) about 2 hours ago (isn't working at home great?), but I can't seem to
>>
>>1. Get a String "Apr 12, 2003" into a Calendar object;
>>2. Test the day of the week the date represents.
>>
>>Clues?  :-)
>>
>>tia,
>>Mark
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>  
>

-- 
Your favorite stores, helpful shopping tools and great gift ideas. 
Experience the convenience of buying online with Shop@Netscape! 
http://shopnow.netscape.com/


RE: [OT] General Java Question: java.util.Calendar

Posted by Mark Galbreath <ma...@qat.com>.
I mean, why didn't Gosling ( or whomever architected the Calendar class )
realize that it MIGHT be nice if the class could take a String date and
convert it to a Calendar object????

Mark

-----Original Message-----
From: Mark Galbreath [mailto:mark_galbreath@qat.com] 
Sent: Thursday, May 22, 2003 8:20 PM
To: 'Struts Users Mailing List'
Subject: RE: [OT] General Java Question: java.util.Calendar


JSP <html:form> <html:text> User enters a date and I need to verify that it
lands on a Saturday.  This is so simple to do client-side, but I'm having a
hellava time getting validation on the server.

Mark

-----Original Message-----
From: Hunter Hillegas [mailto:lists@lastonepicked.com] 
Sent: Thursday, May 22, 2003 8:02 PM
To: Struts List
Subject: Re: [OT] General Java Question: java.util.Calendar


Where are you inputting from?

I know that some of the JSTL tags make it easy to get a date in, and the
format you described shouldn't be a prob.


> From: "Mark Galbreath" <ma...@qat.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Thu, 22 May 2003 19:57:04 -0400
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Subject: [OT] General Java Question: java.util.Calendar
> 
> Okay, I've been working for 12 hours straight and started boozing (Jim
> Beam
> ) about 2 hours ago (isn't working at home great?), but I can't seem to
> 
> 1. Get a String "Apr 12, 2003" into a Calendar object;
> 2. Test the day of the week the date represents.
> 
> Clues?  :-)
> 
> tia,
> Mark
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: [OT] General Java Question: java.util.Calendar

Posted by Mark Galbreath <ma...@qat.com>.
JSP <html:form> <html:text> User enters a date and I need to verify that it
lands on a Saturday.  This is so simple to do client-side, but I'm having a
hellava time getting validation on the server.

Mark

-----Original Message-----
From: Hunter Hillegas [mailto:lists@lastonepicked.com] 
Sent: Thursday, May 22, 2003 8:02 PM
To: Struts List
Subject: Re: [OT] General Java Question: java.util.Calendar


Where are you inputting from?

I know that some of the JSTL tags make it easy to get a date in, and the
format you described shouldn't be a prob.


> From: "Mark Galbreath" <ma...@qat.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Thu, 22 May 2003 19:57:04 -0400
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Subject: [OT] General Java Question: java.util.Calendar
> 
> Okay, I've been working for 12 hours straight and started boozing (Jim 
> Beam
> ) about 2 hours ago (isn't working at home great?), but I can't seem to
> 
> 1. Get a String "Apr 12, 2003" into a Calendar object;
> 2. Test the day of the week the date represents.
> 
> Clues?  :-)
> 
> tia,
> Mark
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] General Java Question: java.util.Calendar

Posted by Hunter Hillegas <li...@lastonepicked.com>.
Where are you inputting from?

I know that some of the JSTL tags make it easy to get a date in, and the
format you described shouldn't be a prob.


> From: "Mark Galbreath" <ma...@qat.com>
> Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Date: Thu, 22 May 2003 19:57:04 -0400
> To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
> Subject: [OT] General Java Question: java.util.Calendar
> 
> Okay, I've been working for 12 hours straight and started boozing (Jim Beam
> ) about 2 hours ago (isn't working at home great?), but I can't seem to
> 
> 1. Get a String "Apr 12, 2003" into a Calendar object;
> 2. Test the day of the week the date represents.
> 
> Clues?  :-)
> 
> tia,
> Mark
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org