Java SimpleDateFormat | Set 2
Java SimpleDateFormat | Set 1
More methods of text.SimpleDateFormat class :
- clone() : java.text.SimpleDateFormat.clone() creates a copy of the SimpleDateFormat.
Syntax : public Object clone() Parameters : ------- Return : copy of the SimpleDateFormat
// Java Program illustrating
// use of SimpleDateFormat.clone() method
import
java.text.*;
import
java.util.Calendar;
public
class
NewClass
{
public
static
void
main(String[] args)
throws
InterruptedException
{
// Date Formatter
SimpleDateFormat geek =
new
SimpleDateFormat();
// Initializing calendar Object
Calendar c = Calendar.getInstance();
// Use of clone() :
System.out.println(
"Clone : "
+ geek.clone());
}
}
chevron_rightfilter_noneOutput :
Clone : java.text.SimpleDateFormat@a9427c06
- hashCode() : java.text.SimpleDateFormat.hashCode() returns hash code value for the SimpleDateFormat object.
Syntax : public int hashCode() Parameters : -------- Return : hash code value for the SimpleDateFormat object.
// Java Program illustrating
// use of SimpleDateFormat.hashCode() method
import
java.text.*;
import
java.util.Calendar;
public
class
NewClass
{
public
static
void
main(String[] args)
throws
InterruptedException
{
// Date Formatter
SimpleDateFormat geek =
new
SimpleDateFormat();
// Initializing calendar Object
Calendar c = Calendar.getInstance();
// Use of hashCode() :
System.out.println(
"Hash Code : "
+ geek.hashCode());
}
}
chevron_rightfilter_noneOutput :
Hash Code : -1455260666
- equals(Object obj) : java.text.SimpleDateFormat.equals(Object obj) compares two SimpleDateFormat objects
Syntax : public boolean equals(Object obj) Parameters : obj : object to compare with Return : true, if equal ; else false
// Java Program illustrating
// use of SimpleDateFormat.equals() method
import
java.text.*;
import
java.util.Calendar;
public
class
NewClass
{
public
static
void
main(String[] args)
throws
InterruptedException, ParseException
{
// Setting formatter
SimpleDateFormat geek =
new
SimpleDateFormat();
geek.applyPattern(
"MMM"
);
// Use of equals() :
System.out.println(
"Is equal ? : "
+
geek.equals(
new
SimpleDateFormat()));
}
}
chevron_rightfilter_noneOutput :
Is equal ? : false
- setDateFormatSymbols(DateFormatSymbols newSymbols) : java.text.SimpleDateFormat.setDateFormatSymbols(DateFormatSymbols newSymbols) sets date and time format symbols of the required date format.
Syntax : public void setDateFormatSymbols(DateFormatSymbols newSymbols) Parameters : newSymbols : new format symbols for data and time Return : -------
// Java Program illustrating
// use of DateFormatSymbols() method
import
java.text.*;
import
java.util.*;
public
class
NewClass
{
public
static
void
main(String[] args)
throws
InterruptedException, ParseException
{
DateFormatSymbols format_symb =
new
DateFormatSymbols(
new
Locale(
"en"
,
"US"
));
String[] days = format_symb.getShortWeekdays();
int
j =
1
;
for
(
int
i =
1
; i < days.length; i++)
{
System.out.print(
"Day"
+ j++ +
" : "
+ days[i] +
"\n"
);
}
}
}
chevron_rightfilter_noneOutput :
Day1 : Sun Day2 : Mon Day3 : Tue Day4 : Wed Day5 : Thu Day6 : Fri Day7 : Sat
- getDateFormatSymbols() : java.text.SimpleDateFormat.getDateFormatSymbols()returns the copy of the date and time format symbols.
Syntax : public DateFormatSymbols getDateFormatSymbols() Parameters : ------- Return : date and time format symbols.
// Java Program illustrating
// use of getDateFormatSymbols() method
import
java.text.*;
import
java.util.*;
public
class
NewClass
{
public
static
void
main(String[] args)
throws
InterruptedException, ParseException
{
SimpleDateFormat geeks =
new
SimpleDateFormat();
String g_date = geeks.format(
new
Date());
// Use of getDateFormatSymbols () :
System.out.println(
""
+ geeks.getDateFormatSymbols());
System.out.println(
"Date : "
+ g_date);
}
}
chevron_rightfilter_noneOutput :
java.text.DateFormatSymbols@f86e64e0 Date : 6/24/17 12:49 PM
- applyLocalizedPattern(String str) : java.text.SimpleDateFormat.applyLocalizedPattern(String str) applies the given localized string pattern to date format.
Syntax : public void applyLocalizedPattern(String str) Parameters : str : string pattern set to new date and time format Return : -------
// Java Program illustarting
// use of applyLocalizedPattern() method
import
java.text.*;
import
java.util.Calendar;
public
class
NewClass
{
public
static
void
main(String[] args)
throws
InterruptedException
{
SimpleDateFormat geek =
new
SimpleDateFormat();
// Initializing calender Object
Calendar c = Calendar.getInstance();
// Using 'arg' pattern
String arg =
"MM / dd / yy HH:mm Z"
;
// Use of applyLocalizedPattern()
geek.applyLocalizedPattern(arg);
System.out.println("Use of applyLocalizedPattern()
: "+geek.toLocalizedPattern());
}
}
chevron_rightfilter_noneOutput :
Use of applyLocalizedPattern() : MM / dd / yy HH:mm Z
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Java SimpleDateFormat | Set 1
- SimpleDateFormat set2DigitYearStart() Method in Java with Examples
- SimpleDateFormat applyPattern() Method in Java with Examples
- SimpleDateFormat toLocalizedPattern() Method in Java with Examples
- SimpleDateFormat parse() Method in Java with Examples
- SimpleDateFormat format() Method in Java with Examples
- SimpleDateFormat hashCode() Method in Java with Examples
- SimpleDateFormat setDateFormatSymbols() Method in Java with Examples
- SimpleDateFormat equals() Method in Java with Examples
- SimpleDateFormat clone() Method in Java with Examples
- SimpleDateFormat applyLocalizedPattern() Method in Java with Examples
- SimpleDateFormat getDateFormatSymbols() Method in Java with Examples
- Change Gregorian Calendar to SimpleDateFormat in Java
- SimpleDateFormat get2DigitYearStart() Method in Java with Examples
- SimpleDateFormat toPattern() Method in Java with Examples