Results 1 to 4 of 4

Thread: UTC Dates

  1. #1
    PedroCosta is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default UTC Dates

    Hello.

    I already search by this topic in the forum searh engine , and i have found a lot of issues related with this topic but none of these have clarified me.
    I read that when you create a Date object like this away Date d = new Date(); , that will contain the date in UTC(number of miliseconds since 01/01/1970), but when i simple
    do System.out.println(d) this will print the date in my local machine timezone.
    How can I have a Date object with the UTC time ?

    Thanks

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Use SimpleDateFormat to format the date string output. If you read the API docs for Date and it's toString method (which is what at work there) it clearly states that the date will presented in the machines local timezone, but the actual date object is still a UTC Date Time representation, you are simply seeing the String representation of that time in your timezone when you use toString().

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,298
    Rep Power
    20

Similar Threads

  1. Times without dates.
    By JavaJuJitZu in forum Advanced Java
    Replies: 14
    Last Post: 01-17-2010, 10:54 PM
  2. Adding dates how can i do that
    By kirtichopra2003 in forum Advanced Java
    Replies: 7
    Last Post: 10-12-2009, 11:27 AM
  3. Difference of Two Dates
    By jboy in forum New To Java
    Replies: 3
    Last Post: 09-15-2009, 06:41 PM
  4. JTable and Dates
    By paluee in forum AWT / Swing
    Replies: 0
    Last Post: 03-30-2009, 08:02 PM
  5. Help with dates
    By bumblyb33 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 02:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •