
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 33676 Articles for Programming

178 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

295 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

191 Views
The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string. To parse a date string −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample { public static void main(String args[]) throws ParseException { SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss"); Date time1 = formatter1.parse("07:25:30"); System.out.println("Date value: "+time1); SimpleDateFormat formatter3 = new SimpleDateFormat("hh 'o''clock' a"); Date time3 = formatter3.parse("09 ... Read More

462 Views
Using the LocalDate classThe java.time.LocalDate class represents the local date i.e. the date without time zone, you can use this object instead of Date. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two dates −ExampleLive Demoimport java.time.LocalDate; public class Sample { public static void main(String args[]) { LocalDate date1 = LocalDate.of(2007, 11, 25); LocalDate date2 = LocalDate.of(1999, 9, 12); Boolean bool1 = date1.isAfter(date2); Boolean bool2 = date1.isBefore(date2); Boolean bool3 = date1.isEqual(date2); if(bool1){ ... Read More

7K+ Views
The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.One 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 object Instantiate this class by passing desired format string.Parse the date string using the parse() method.The util.Date class represents a specific instant time This class provides various methods such as before(), after() and, equals() to compare two datesExampleOnce you create date objects from strings you can compare them using either of these methods as shown below −Live Demoimport java.text.ParseException; ... Read More

2K+ Views
The LocalTime class represents the local time i.e. the time without time zone. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two times.ExampleLive Demoimport java.time.LocalTime; public class Test { public static void main(String args[]) { LocalTime Time1 = LocalTime.of(10, 15, 45); LocalTime Time2 = LocalTime.of(07, 25, 55); Boolean bool1 = Time1.isAfter(Time2); Boolean bool2 = Time1.isBefore(Time2); if(bool1){ System.out.println(Time1+" is after "+Time2); }else if(bool2){ System.out.println(Time1+" ... Read More

894 Views
The java.time.LocalDateTime class represents the local date and time i.e. the date without time zone, you can use this object instead of Date. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two dates −ExampleLive Demoimport java.time.LocalDateTime; public class Test { public static void main(String args[]) { LocalDateTime dateTime1 = LocalDateTime.of(2007, 11, 25, 10, 15, 45); LocalDateTime dateTime2 = LocalDateTime.of(1999, 9, 12, 07, 25, 55); Boolean bool1 = dateTime1.isAfter(dateTime2); Boolean bool2 = dateTime1.isBefore(dateTime2); Boolean bool3 = ... Read More

294 Views
One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat class. To parse/convert a string as a Date object −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample { public static void main(String args[]) throws ParseException { String date_string = "2007-25-06"; //Instantiating the SimpleDateFormat class SimpleDateFormat formatter = new SimpleDateFormat("yyyy-dd-MM"); //Parsing the given String to Date object Date ... Read More

2K+ Views
Using the SimpleDateFormat classOne of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat class. To parse/convert a string as a Date object −Instantiate this class by passing desired format string.Parse the date string using the parse() method.ExampleLive Demoimport java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Sample { public static void main(String args[]) throws ParseException { String date_string = "2007-25-06"; //Instantiating the SimpleDateFormat class SimpleDateFormat formatter = new SimpleDateFormat("yyyy-dd-MM"); //Parsing the given String to Date object ... Read More

9K+ Views
To change the name of a data frame, we can set the original name to the new name. Now both of the names can be used. Most of the times the purpose behind changing the name of the data frame is that, the original name does not seem to be a valid name based on the characteristics of the data. For example, if we have normally distributed columns in the data frame then we can name it as normal_distribution. This will help everyone to understand the data belongs to normal distribution.Example1 Live Demoset.seed(24) x