• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Different output converting dates to msecs!

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have really some problems with the Date Class!

The aim is to manage timestamp in msec, in order to store them
in a sql db so I can use the BETWEEN clause.



I try this code:



and the output is:



The problem is the second line of output, I was expecting the same long number as the others!
Why the difference ?
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you format from the milli seconds check if there is any GMT addition in the date by giving like below.
 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:When you format from the milli seconds check if there is any GMT addition in the date by giving like below.



Thanks for the reply!
In my project I never need to store the time, I only care about the date.
Any advice to get rid of these problems when I am using ms, since I don't care about the time ?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alessandro Camel wrote:

John Jai wrote:When you format from the milli seconds check if there is any GMT addition in the date by giving like below.



Thanks for the reply!
In my project I never need to store the time, I only care about the date.
Any advice to get rid of these problems when I am using ms, since I don't care about the time ?



Which problem? The GMT addition?
 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raphael Onofre wrote:

Alessandro Camel wrote:

John Jai wrote:When you format from the milli seconds check if there is any GMT addition in the date by giving like below.



Thanks for the reply!
In my project I never need to store the time, I only care about the date.
Any advice to get rid of these problems when I am using ms, since I don't care about the time ?



Which problem? The GMT addition?



Yes, this and every problem could be in place when using data/time strings when I care only only about the data..
 
Raphael Onofre
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Brazil(my country) is used (GMT-3).

So, if i have to get the correct time in Java we can do:

3h = 10800000 millisec

Thus,


 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is worth looking at the TimeUnit enum, which might make such calculations easier.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic