Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Timestamp

Reply
Thread Tools

Timestamp

 
 
angelochen960@gmail.com
Guest
Posts: n/a
 
      03-01-2009
Hi,

I have a variable:

java.sql.Timestamp timeNow;

I'd like to get another Timestamp variable that is 6 hours from
timeNow, how to do this? Thanks,

Angelo
 
Reply With Quote
 
 
 
 
RedGrittyBrick
Guest
Posts: n/a
 
      03-01-2009

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I have a variable:
>
> java.sql.Timestamp timeNow;
>
> I'd like to get another Timestamp variable that is 6 hours from
> timeNow, how to do this? Thanks,
>


You could use java.util.Calendar,
http://blogs.techrepublic.com.com/howdoi/?p=116.

Obviously, you'll have to convert from java.sql.Timestamp to
java.util.Calendar and back again.

Or wait for JSR 310?

--
RGB
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      03-01-2009
(E-Mail Removed) wrote:
>> I have a variable:
>>
>> java.sql.Timestamp timeNow;
>>
>> I'd like to get another Timestamp variable that is 6 hours from
>> timeNow, how to do this? Thanks,


RedGrittyBrick wrote:
> You could use java.util.Calendar,
> http://blogs.techrepublic.com.com/howdoi/?p=116.
>
> Obviously, you'll have to convert from java.sql.Timestamp to
> java.util.Calendar and back again.
>
> Or wait for JSR 310?


More information about Calendar:
<http://java.sun.com/javase/6/docs/api/java/util/Calendar.html>

--
Lew
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      03-01-2009
(E-Mail Removed) wrote:
> I have a variable:
>
> java.sql.Timestamp timeNow;
>
> I'd like to get another Timestamp variable that is 6 hours from
> timeNow, how to do this? Thanks,


Timestamp ts2 = new Timestamp(ts1.getTime() + 6 * 60 * 60 * 1000L);

Arne
 
Reply With Quote
 
Mark Thornton
Guest
Posts: n/a
 
      03-01-2009
Arne Vajh°j wrote:
> (E-Mail Removed) wrote:
>> I have a variable:
>>
>> java.sql.Timestamp timeNow;
>>
>> I'd like to get another Timestamp variable that is 6 hours from
>> timeNow, how to do this? Thanks,

>
> Timestamp ts2 = new Timestamp(ts1.getTime() + 6 * 60 * 60 * 1000L);
>
> Arne


Unless the OP wants a 6 hour wall clock difference in which case it
might be necessary to allow for standard/daylight time transitions.
Currently Calendar is the best way to solve that case.

Mark Thornton
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      03-01-2009
Mark Thornton wrote:
> Arne Vajh°j wrote:
>> (E-Mail Removed) wrote:
>>> I have a variable:
>>>
>>> java.sql.Timestamp timeNow;
>>>
>>> I'd like to get another Timestamp variable that is 6 hours from
>>> timeNow, how to do this? Thanks,

>>
>> Timestamp ts2 = new Timestamp(ts1.getTime() + 6 * 60 * 60 * 1000L);

>
> Unless the OP wants a 6 hour wall clock difference in which case it
> might be necessary to allow for standard/daylight time transitions.
> Currently Calendar is the best way to solve that case.


The above +6 hours in time.

Calendar can be used to get +6 hours on the clock, but the code
would not be a simple add.

Arne
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-01-2009
Arne Vajh├Şj wrote:
> Mark Thornton wrote:
>> Arne Vajh├Şj wrote:
>>> (E-Mail Removed) wrote:
>>>> I have a variable:
>>>>
>>>> java.sql.Timestamp timeNow;
>>>>
>>>> I'd like to get another Timestamp variable that is 6 hours from
>>>> timeNow, how to do this? Thanks,
>>>
>>> Timestamp ts2 = new Timestamp(ts1.getTime() + 6 * 60 * 60 * 1000L);

>>
>> Unless the OP wants a 6 hour wall clock difference in which case it
>> might be necessary to allow for standard/daylight time transitions.
>> Currently Calendar is the best way to solve that case.

>
> The above +6 hours in time.
>
> Calendar can be used to get +6 hours on the clock, but the code
> would not be a simple add.


Depends on how simple you demand that "simple" be.

I see nothing too complex about:

Calendar cal = Calendar.getInstance();
cal.setTime( timeNow );
cal.add( Calendar.HOUR_OF_DAY, 6 );
Timestamp futre = new Timestamp( cal.getTimeInMillis() );

Actually this is easier to read, I think, than the 'ts2' calculation above,
and has the virtue of accounting for DST.

--
Lew
 
Reply With Quote
 
Arne Vajh├Şj
Guest
Posts: n/a
 
      03-01-2009
Lew wrote:
> Arne Vajh├Şj wrote:
>> Mark Thornton wrote:
>>> Arne Vajh├Şj wrote:
>>>> (E-Mail Removed) wrote:
>>>>> I have a variable:
>>>>>
>>>>> java.sql.Timestamp timeNow;
>>>>>
>>>>> I'd like to get another Timestamp variable that is 6 hours from
>>>>> timeNow, how to do this? Thanks,
>>>>
>>>> Timestamp ts2 = new Timestamp(ts1.getTime() + 6 * 60 * 60 * 1000L);
>>>
>>> Unless the OP wants a 6 hour wall clock difference in which case it
>>> might be necessary to allow for standard/daylight time transitions.
>>> Currently Calendar is the best way to solve that case.

>>
>> The above +6 hours in time.
>>
>> Calendar can be used to get +6 hours on the clock, but the code
>> would not be a simple add.

>
> Depends on how simple you demand that "simple" be.
>
> I see nothing too complex about:
>
> Calendar cal = Calendar.getInstance();
> cal.setTime( timeNow );
> cal.add( Calendar.HOUR_OF_DAY, 6 );
> Timestamp futre = new Timestamp( cal.getTimeInMillis() );


Hm.

That code does +6 hours in time not the +6 hours on clock that
I called "would not be a simple add".

> Actually this is easier to read, I think, than the 'ts2' calculation
> above,


It is more readable.

> and has the virtue of accounting for DST.


It does the exact same as my code regarding changes to and from DST.

Arne
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert to NTP Timestamp Manzoorul Hassan Perl 1 03-11-2005 05:37 PM
filter ICMP timestamp request on Cisco router or PIX szehun@gmail.com Cisco 1 12-16-2004 09:44 AM
filter ICMP timestamp request on Cisco router or PIX szehun@gmail.com Cisco 0 12-16-2004 08:55 AM
PIX logging without timestamp Ste Cisco 2 09-04-2004 01:08 AM
log timestamp format Bill F Cisco 3 07-24-2003 05:40 AM



Advertisments