Solved

Generating Current time...

Posted on 2001-06-08
4
171 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now