• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Date and Time

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a simple question
Can anyone tell me how to get the date and time of the system?
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pete,
when you initialize a Date with an empty constructor (Date date = new Date();) then it is initialized with the current Date and Time on your computer. Is this what you mean?
Rene
[ July 10, 2002: Message edited by: Rene Liebmann ]
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, sort of. I need to enter the date and time into a database. So i need to be able to return the date and time in a specific format i.e. if the date and time was July 10th 2002 9:45 i would need the:
date : 2002-07-10
time : 09:45:00
the api isn't very clear on how to achieve this. Can you help?
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this link:
http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
/Rene
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, SimpleDateFormat could be one solution. Another Possibility is the Calendar (GregorianCalendar). If you create a new GregorianCalendar then it already is initialized with the current time. Then the Calendar object has lots of methods to get what you want. Therefore the API has a good example.
Good luck
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When using the Calendar class, do take care of this functionality regd. month...
Use this URL for more info

MSM
 
Peter Phung
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used SimpleDateFormat because that's all i needed.
Thanks to both Rene's, your help was much appreciated.
 
No, tomorrow we rule the world! With this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic