Solved

Generating Current time...

Posted on 2001-06-08
4
173 Views
Last Modified: 2013-12-03
Dear expert...

can any of you provide me with the code how to generate current time in java...i need it urgently..thank !

from : Alex Gan
0
Comment
Question by:kgsoft_sys
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
Ovi earned 18 total points
ID: 6167162
Date curent_date = new Date();
if you do : System.out.println("Created date : " + curent_date.toString()); will be printed out the curent date
that's all. If you want more than that (i.e. working with the year, month, etc ...) You must use an instance of java.util.Calendar or java.util.GregorianCalendar. Please fill free to ask.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6167215
public class DateGenerator {
  public static void main(String[] args) {
    System.out.println("Curent date is : " + (new Date()).toString());
  }
}

Compile this and run'it.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 6171115
System.currentTimeMillis() produces the current time in milliseconds with a resolution dependent upon your the native system's clock.

java.util.Date wraps the millisecond value and provides some comparison behavior although most of its useful behavior has been deprecated and moved to java.util.Calendar and its concrete subclasses. The no-arg constructor of Date initializes the new Date object with the current time provided by System.currentTimeMillis().

java.util.Calendar provides facilities for getting and setting specific date parts (like seconds, months, years) and for performing date arithmetic.

java.text.DateFormat and its more useful class java.text.SimpleDateFormat perform Date formatting to Strings and parsing from Strings.

Taken together, one or more of these classes is likely to have the functionality you are looking for with respect to "generating the current time".

Best regards,
Jim Cakalic
0
 
LVL 1

Expert Comment

by:prasad2000
ID: 6176500
DateFormat dateFormat = DateFormat.getDateInstance();
Calendar calender = dateFormat.getCalendar();
System.out.println("time"+calender.getTime());
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to count occurrences of each item in an array.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question