You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by ba...@liga.net on 2006/10/07 01:58:02 UTC

Can I create date with jakarta commons

Good day!

I need sometimes to create concrete Date object. I have the function to do
it now:

      public static Date createDate(int year, int month, int day){
            Calendar calendar = Calendar.getInstance();

            calendar.set(year, month, day, 0, 0, 0);
            calendar.set(Calendar.MILLISECOND, 0);

            return calendar.getTime();
      }

Is there such function in commons?

Thanks!

_____________
With best regards,
Vitaly Baranovsky


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


Re: [lang] Can I create date with jakarta commons

Posted by Stephen Colebourne <sc...@btopenworld.com>.
There is no such function at present. Feel free to add a request in JIRA.
Stephen

baranovsky@liga.net wrote:
> Good day!
> 
> I need sometimes to create concrete Date object. I have the function to do
> it now:
> 
>       public static Date createDate(int year, int month, int day){
>             Calendar calendar = Calendar.getInstance();
> 
>             calendar.set(year, month, day, 0, 0, 0);
>             calendar.set(Calendar.MILLISECOND, 0);
> 
>             return calendar.getTime();
>       }
> 
> Is there such function in commons?
> 
> Thanks!
> 
> _____________
> With best regards,
> Vitaly Baranovsky
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 

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


Re: [SPAM] - Can I create date with jakarta commons - Email has different SMTP TO: and MIME TO: fields in the email addresses

Posted by Chris Cheshire <ch...@gmail.com>.
Use a java.text.SimpleDateFormat.

Date d = new SimpleDateFormat("yyyyMMdd").parse("20061225", new
ParsePosition(0));

If you use a format a lot, create a static instance of the
SimpleDateFormat and just reference parse() on that object as needed.

HTH

Chris

On 10/6/06, baranovsky@liga.net <ba...@liga.net> wrote:
> Hmm...
>
> But I need create java.util.Date object with concrete Date. Can I do this
> using one row of code? Is there something like createDate(2006, 11, 25)
> that returns java.util.Date?
>
> Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 03:47:42:
>
> > Hi, Vitaly,
> >
> > Try java.util.GregorianCalendar!
> >
> > // Christmas is December 25th.
> > Calendar c = new GregorianCalendar( 2006, 11, 25 );
> >
> > // 1 second after this coming New Years:
> > int year = 2007;
> > int month = 0; // January is 0
> > int dayOfMonth = 1;
> > int hourOfDay = 0;
> > int minute = 0;
> > int second = 1;
> > c = new GregorianCalendar( year, month, dayOfMonth, hourOfDay,
> > minute, second );
> >
> >
> > yours,
> >
> > Julius
> >
> > http://juliusdavies.ca/
> >
> >
> > On Sat, 2006-07-10 at 02:58 +0300, baranovsky@liga.net wrote:
> > > Good day!
> > >
> > > I need sometimes to create concrete Date object. I have the function to
> do
> > > it now:
> > >
> > >       public static Date createDate(int year, int month, int day){
> > >             Calendar calendar = Calendar.getInstance();
> > >
> > >             calendar.set(year, month, day, 0, 0, 0);
> > >             calendar.set(Calendar.MILLISECOND, 0);
> > >
> > >             return calendar.getTime();
> > >       }
> > >
> > > Is there such function in commons?
> > >
> > > Thanks!
> > >
> > > _____________
> > > With best regards,
> > > Vitaly Baranovsky
> > >
> > >

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


Re: Can I create date with jakarta commons

Posted by Julius Davies <ju...@cucbc.com>.
Hi, Vitaly,

Try the following code:

DateFormat df = new SimpleDateFormat( "yyyy-MM-dd/HH:mm:ss.SSS" );
Date d = new GregorianCalendar( 2006, 11, 25 ).getTime();
System.out.println( df.format( d ) );
System.out.println( d );

Prints out:
======================
2006-12-25/00:00:00.000
Mon Dec 25 00:00:00 PST 2006

It might print a different timezone than "PST" for you.

If you look inside the actual source code for java.util.GregorianCalendar, you'll see this constructor:

public GregorianCalendar(int year, int month, int dayOfMonth) {
  this(year, month, dayOfMonth, 0, 0, 0, 0);
}

Those zeroes are for hour, minute, second, millisecond.

yours,

Julius


On Sat, 2006-07-10 at 17:38 +0300, baranovsky@liga.net wrote:
> This code return Date object with current time part include milliseconds.
> 
> For example, is I run this code now, it returns me Date object "2006.11.25
> 17:36:06 116ms", because 17:36 o'clock now
> 
> Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 17:23:49:
> 
> > Date d = new GregorianCalendar( 2006, 11, 25 ).getTime();
> >
> >
> > On Sat, 2006-07-10 at 04:05 +0300, baranovsky@liga.net wrote:
> > > Hmm...
> > >
> > > But I need create java.util.Date object with concrete Date. Can I do
> this
> > > using one row of code? Is there something like createDate(2006, 11, 25)
> > > that returns java.util.Date?
> > >
> > > Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 03:47:42:
> > >
> > > > Hi, Vitaly,
> > > >
> > > > Try java.util.GregorianCalendar!
> > > >
> > > > // Christmas is December 25th.
> > > > Calendar c = new GregorianCalendar( 2006, 11, 25 );
> > > >
> > > > // 1 second after this coming New Years:
> > > > int year = 2007;
> > > > int month = 0; // January is 0
> > > > int dayOfMonth = 1;
> > > > int hourOfDay = 0;
> > > > int minute = 0;
> > > > int second = 1;
> > > > c = new GregorianCalendar( year, month, dayOfMonth, hourOfDay,
> > > > minute, second );
> > > >
> > > >
> > > > yours,
> > > >
> > > > Julius
> > > >
> > > > http://juliusdavies.ca/
> > > >
> > > >
> > > > On Sat, 2006-07-10 at 02:58 +0300, baranovsky@liga.net wrote:
> > > > > Good day!
> > > > >
> > > > > I need sometimes to create concrete Date object. I have the
> function to
> > > do
> > > > > it now:
> > > > >
> > > > >       public static Date createDate(int year, int month, int day){
> > > > >             Calendar calendar = Calendar.getInstance();
> > > > >
> > > > >             calendar.set(year, month, day, 0, 0, 0);
> > > > >             calendar.set(Calendar.MILLISECOND, 0);
> > > > >
> > > > >             return calendar.getTime();
> > > > >       }
> > > > >
> > > > > Is there such function in commons?
> > > > >
> > > > > Thanks!
> > > > >
> > > > > _____________
> > > > > With best regards,
> > > > > Vitaly Baranovsky
> > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> > > > >
> > > > --
> > > > Julius Davies
> > > > Senior Application Developer, Technology Services
> > > > Credit Union Central of British Columbia
> > > > http://www.cucbc.com/
> > > > Tel: 416-652-0183
> > > > Cel: 647-232-7571
> > > >
> > > > 1441 Creekside Drive
> > > > Vancouver, BC
> > > > Canada
> > > > V6J 4S7
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> > --
> > Julius Davies
> > Senior Application Developer, Technology Services
> > Credit Union Central of British Columbia
> > http://www.cucbc.com/
> > Tel: 416-652-0183
> > Cel: 647-232-7571
> >
> > 1441 Creekside Drive
> > Vancouver, BC
> > Canada
> > V6J 4S7
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
-- 
Julius Davies
Senior Application Developer, Technology Services
Credit Union Central of British Columbia
http://www.cucbc.com/
Tel: 416-652-0183
Cel: 647-232-7571

1441 Creekside Drive
Vancouver, BC
Canada
V6J 4S7


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


Re: Can I create date with jakarta commons

Posted by ba...@liga.net.
This code return Date object with current time part include milliseconds.

For example, is I run this code now, it returns me Date object "2006.11.25
17:36:06 116ms", because 17:36 o'clock now

Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 17:23:49:

> Date d = new GregorianCalendar( 2006, 11, 25 ).getTime();
>
>
> On Sat, 2006-07-10 at 04:05 +0300, baranovsky@liga.net wrote:
> > Hmm...
> >
> > But I need create java.util.Date object with concrete Date. Can I do
this
> > using one row of code? Is there something like createDate(2006, 11, 25)
> > that returns java.util.Date?
> >
> > Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 03:47:42:
> >
> > > Hi, Vitaly,
> > >
> > > Try java.util.GregorianCalendar!
> > >
> > > // Christmas is December 25th.
> > > Calendar c = new GregorianCalendar( 2006, 11, 25 );
> > >
> > > // 1 second after this coming New Years:
> > > int year = 2007;
> > > int month = 0; // January is 0
> > > int dayOfMonth = 1;
> > > int hourOfDay = 0;
> > > int minute = 0;
> > > int second = 1;
> > > c = new GregorianCalendar( year, month, dayOfMonth, hourOfDay,
> > > minute, second );
> > >
> > >
> > > yours,
> > >
> > > Julius
> > >
> > > http://juliusdavies.ca/
> > >
> > >
> > > On Sat, 2006-07-10 at 02:58 +0300, baranovsky@liga.net wrote:
> > > > Good day!
> > > >
> > > > I need sometimes to create concrete Date object. I have the
function to
> > do
> > > > it now:
> > > >
> > > >       public static Date createDate(int year, int month, int day){
> > > >             Calendar calendar = Calendar.getInstance();
> > > >
> > > >             calendar.set(year, month, day, 0, 0, 0);
> > > >             calendar.set(Calendar.MILLISECOND, 0);
> > > >
> > > >             return calendar.getTime();
> > > >       }
> > > >
> > > > Is there such function in commons?
> > > >
> > > > Thanks!
> > > >
> > > > _____________
> > > > With best regards,
> > > > Vitaly Baranovsky
> > > >
> > > >
> > > >
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
commons-user-help@jakarta.apache.org
> > > >
> > > --
> > > Julius Davies
> > > Senior Application Developer, Technology Services
> > > Credit Union Central of British Columbia
> > > http://www.cucbc.com/
> > > Tel: 416-652-0183
> > > Cel: 647-232-7571
> > >
> > > 1441 Creekside Drive
> > > Vancouver, BC
> > > Canada
> > > V6J 4S7
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> --
> Julius Davies
> Senior Application Developer, Technology Services
> Credit Union Central of British Columbia
> http://www.cucbc.com/
> Tel: 416-652-0183
> Cel: 647-232-7571
>
> 1441 Creekside Drive
> Vancouver, BC
> Canada
> V6J 4S7
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


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


Re: Can I create date with jakarta commons

Posted by Julius Davies <ju...@cucbc.com>.
Date d = new GregorianCalendar( 2006, 11, 25 ).getTime();


On Sat, 2006-07-10 at 04:05 +0300, baranovsky@liga.net wrote:
> Hmm...
> 
> But I need create java.util.Date object with concrete Date. Can I do this
> using one row of code? Is there something like createDate(2006, 11, 25)
> that returns java.util.Date?
> 
> Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 03:47:42:
> 
> > Hi, Vitaly,
> >
> > Try java.util.GregorianCalendar!
> >
> > // Christmas is December 25th.
> > Calendar c = new GregorianCalendar( 2006, 11, 25 );
> >
> > // 1 second after this coming New Years:
> > int year = 2007;
> > int month = 0; // January is 0
> > int dayOfMonth = 1;
> > int hourOfDay = 0;
> > int minute = 0;
> > int second = 1;
> > c = new GregorianCalendar( year, month, dayOfMonth, hourOfDay,
> > minute, second );
> >
> >
> > yours,
> >
> > Julius
> >
> > http://juliusdavies.ca/
> >
> >
> > On Sat, 2006-07-10 at 02:58 +0300, baranovsky@liga.net wrote:
> > > Good day!
> > >
> > > I need sometimes to create concrete Date object. I have the function to
> do
> > > it now:
> > >
> > >       public static Date createDate(int year, int month, int day){
> > >             Calendar calendar = Calendar.getInstance();
> > >
> > >             calendar.set(year, month, day, 0, 0, 0);
> > >             calendar.set(Calendar.MILLISECOND, 0);
> > >
> > >             return calendar.getTime();
> > >       }
> > >
> > > Is there such function in commons?
> > >
> > > Thanks!
> > >
> > > _____________
> > > With best regards,
> > > Vitaly Baranovsky
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> > --
> > Julius Davies
> > Senior Application Developer, Technology Services
> > Credit Union Central of British Columbia
> > http://www.cucbc.com/
> > Tel: 416-652-0183
> > Cel: 647-232-7571
> >
> > 1441 Creekside Drive
> > Vancouver, BC
> > Canada
> > V6J 4S7
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
-- 
Julius Davies
Senior Application Developer, Technology Services
Credit Union Central of British Columbia
http://www.cucbc.com/
Tel: 416-652-0183
Cel: 647-232-7571

1441 Creekside Drive
Vancouver, BC
Canada
V6J 4S7


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


Re: [SPAM] - Can I create date with jakarta commons - Email has different SMTP TO: and MIME TO: fields in the email addresses

Posted by ba...@liga.net.
Hmm...

But I need create java.util.Date object with concrete Date. Can I do this
using one row of code? Is there something like createDate(2006, 11, 25)
that returns java.util.Date?

Julius Davies <ju...@cucbc.com> wrote on 07.10.2006 03:47:42:

> Hi, Vitaly,
>
> Try java.util.GregorianCalendar!
>
> // Christmas is December 25th.
> Calendar c = new GregorianCalendar( 2006, 11, 25 );
>
> // 1 second after this coming New Years:
> int year = 2007;
> int month = 0; // January is 0
> int dayOfMonth = 1;
> int hourOfDay = 0;
> int minute = 0;
> int second = 1;
> c = new GregorianCalendar( year, month, dayOfMonth, hourOfDay,
> minute, second );
>
>
> yours,
>
> Julius
>
> http://juliusdavies.ca/
>
>
> On Sat, 2006-07-10 at 02:58 +0300, baranovsky@liga.net wrote:
> > Good day!
> >
> > I need sometimes to create concrete Date object. I have the function to
do
> > it now:
> >
> >       public static Date createDate(int year, int month, int day){
> >             Calendar calendar = Calendar.getInstance();
> >
> >             calendar.set(year, month, day, 0, 0, 0);
> >             calendar.set(Calendar.MILLISECOND, 0);
> >
> >             return calendar.getTime();
> >       }
> >
> > Is there such function in commons?
> >
> > Thanks!
> >
> > _____________
> > With best regards,
> > Vitaly Baranovsky
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> --
> Julius Davies
> Senior Application Developer, Technology Services
> Credit Union Central of British Columbia
> http://www.cucbc.com/
> Tel: 416-652-0183
> Cel: 647-232-7571
>
> 1441 Creekside Drive
> Vancouver, BC
> Canada
> V6J 4S7
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


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


Re: [SPAM] - Can I create date with jakarta commons - Email has different SMTP TO: and MIME TO: fields in the email addresses

Posted by Julius Davies <ju...@cucbc.com>.
Hi, Vitaly,

Try java.util.GregorianCalendar!

// Christmas is December 25th.
Calendar c = new GregorianCalendar( 2006, 11, 25 );

// 1 second after this coming New Years:
int year = 2007;
int month = 0; // January is 0
int dayOfMonth = 1;
int hourOfDay = 0;
int minute = 0;
int second = 1;
c = new GregorianCalendar( year, month, dayOfMonth, hourOfDay, minute, second );


yours,

Julius

http://juliusdavies.ca/


On Sat, 2006-07-10 at 02:58 +0300, baranovsky@liga.net wrote:
> Good day!
> 
> I need sometimes to create concrete Date object. I have the function to do
> it now:
> 
>       public static Date createDate(int year, int month, int day){
>             Calendar calendar = Calendar.getInstance();
> 
>             calendar.set(year, month, day, 0, 0, 0);
>             calendar.set(Calendar.MILLISECOND, 0);
> 
>             return calendar.getTime();
>       }
> 
> Is there such function in commons?
> 
> Thanks!
> 
> _____________
> With best regards,
> Vitaly Baranovsky
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
-- 
Julius Davies
Senior Application Developer, Technology Services
Credit Union Central of British Columbia
http://www.cucbc.com/
Tel: 416-652-0183
Cel: 647-232-7571

1441 Creekside Drive
Vancouver, BC
Canada
V6J 4S7


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