[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Generating Current time...

Posted on 2001-06-08
4
Medium Priority
?
184 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 36 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

649 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