Solved

Generating Current time...

Posted on 2001-06-08
4
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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 …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.

724 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