- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2617 Articles for Java
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
3K+ Views
In general, the elapsed time is the time from the starting point to ending point of an event. Following are various ways to find elapsed time in Java −The nanoTime() method returns the current time in nano seconds. To find the elapsed time for the execution of a method in nano seconds −Retrieve the current time using the nanoTime() method.Execute the desired method.Again, retrieve the current time using the nanoTime() method.Finally, Find the difference between the end value and the start value.ExampleLive Demopublic class Example { public void test(){ int num = 0; for(int i=0; i
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
6K+ Views
In general, the elapsed time or, execution is the time from the starting point to ending point of an event. Following are various ways to find elapsed time in Java −The currentTimeMillis() method returns the current time in milliseconds. To find the elapsed time for a method you can get the difference between time values before and after the execution of the desired method.The nanoTime() method returns the current time in nano seconds. To find the elapsed time for a method you can get the difference between time values before and after the execution of the desired method.The now() method ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
53K+ Views
In general, the elapsed time is the time from the starting point to ending point of an event. Following are various ways to find elapsed time in Java −The currentTimeMillis() method returns the current time in milliseconds. To find the elapsed time for a method you can get the difference between time values before and after the execution of the desired method.The nanoTime() method returns the current time in nano seconds. To find the elapsed time for a method you can get the difference between time values before and after the execution of the desired method.The now() method of the ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
4K+ Views
In general, the elapsed time is the time from the starting point to ending point of an event. Following are various ways to find elapsed time in Java −Using the currentTimeMillis() methodThe currentTimeMillis() method returns the current time in milliseconds. To find the elapsed time for a method you can get the difference between time values before and after the execution of the desired method.ExampleLive Demopublic class Example { public void test(){ int num = 0; for(int i=0; i
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
213 Views
The printf() method is used to print a formatted string, it accepts a string representing a format string and an array of objects representing the elements that are to be in the resultant string, if the number of arguments are more than the number of characters in the format string the excess objects are ignored.Following table lists the various format characters to format time by the Java printf() method along with their description −Format CharactersDescription'H'The corresponding argument is formatted as Hour of the day (00-24).'I'The corresponding argument is formatted as hour of the day (01 -12).'k'The corresponding argument is formatted ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
145 Views
The printf() method is used to print a formatted string, it accepts a string representing a format string and an array of objects representing the elements that are to be in the resultant string, if the number of arguments are more than the number of characters in the format string the excess objects are ignored.Following table lists the various format characters to print date printf() method along with their description −Format CharactersDescription'B'The corresponding argument is formatted as full month name.'b'The corresponding argument is formatted as abbreviated month name.'h'The corresponding argument is formatted as abbreviated month name.'A'The corresponding argument is formatted as ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
896 Views
The GregorianCalendar class supports standard calendars it supports Julian and Gregorian calendars you can create an object of GregorianCalendar using one of its constructors. Following are various examples demonstrating how to print date using this class −ExampleFollowing example creates GregorianCalander by passing year, month and date values as parameters to its constructor and prints the date −Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Test { public static void main(String args[]){ //Instantiating the GregorianCalendar GregorianCalendar cal = new GregorianCalendar(2018, 6, 27); System.out.println(cal); System.out.println("Date: "+cal.get(Calendar.DATE)); System.out.println("Month: ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
You can parse a string containing a data to date value using the following ways −The constructor SimpleDateFormat class accepts a String value representing the desired date format and creates this object. You can parse the date string using the parse() method of this class.The parse() method of the LocalDate class accepts a String value representing a date and returns a LocalDate object.The DateUtils provides utility to format date you can find it in apache.commons package. The parseDate() method of the DateUtils class accepts a format string and a date string as parameters and returns a Date object.The parse() method of ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
120 Views
The format() method of the java.lang.String class accepts a format string and an array of arguments and the string in specified format.ExampleFollowing example formats a date using the format() method −Live Demoimport java.util.Calendar; import java.util.GregorianCalendar; public class Test { public static void main(String args[]){ //Instantiating the GregorianCalendar Calendar cal = GregorianCalendar.getInstance(); System.out.println("Date: "+cal.get(Calendar.DATE)); System.out.println("Month: "+cal.get(Calendar.MONTH)); System.out.println("Year: "+cal.get(Calendar.YEAR)); Object arr[] = { "Date", cal }; System.out.println("Desired Format: "); System.out.println(String.format("%1$s = %2$tY ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
199 Views
The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.Parsing a date stringOne of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat object. To parse/convert a string as a Date objectInstantiate this class by passing desired format string.Parse the date string using the parse() method.Following is the list of letters for formatting with their descriptions and examples −LetterComponentExampleGEra designatorAD, BCyYear2005, 96YWeek year2005, 96MMonth in yearSeptember, Sep, 09LMonth in yearSeptember, Sep, 09wWeek in year23WWeek in month3DDay in year129dDay in month27FDay of week in month5EDay in a ... Read More