Java SimpleDateFormat | Set 2
Last Updated :
17 Jan, 2022
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
import java.text.*;
import java.util.Calendar;
public class NewClass
{
public static void main(String[] args) throws InterruptedException
{
SimpleDateFormat geek = new SimpleDateFormat();
Calendar c = Calendar.getInstance();
System.out.println( "Clone : " + geek.clone());
}
}
|
Output :
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
import java.text.*;
import java.util.Calendar;
public class NewClass
{
public static void main(String[] args) throws InterruptedException
{
SimpleDateFormat geek = new SimpleDateFormat();
Calendar c = Calendar.getInstance();
System.out.println( "Hash Code : " + geek.hashCode());
}
}
|
Output :
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
import java.text.*;
import java.util.Calendar;
public class NewClass
{
public static void main(String[] args)
throws InterruptedException, ParseException
{
SimpleDateFormat geek = new SimpleDateFormat();
geek.applyPattern( "MMM" );
System.out.println( "Is equal ? : " +
geek.equals( new SimpleDateFormat()));
}
}
|
Output :
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
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" );
}
}
}
|
Output :
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
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());
System.out.println( "" + geeks.getDateFormatSymbols());
System.out.println( "Date : " + g_date);
}
}
|
Output :
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
import java.text.*;
import java.util.Calendar;
public class NewClass
{
public static void main(String[] args)
throws InterruptedException
{
SimpleDateFormat geek = new SimpleDateFormat();
Calendar c = Calendar.getInstance();
String arg = "MM / dd / yy HH:mm Z" ;
geek.applyLocalizedPattern(arg);
System.out.println("Use of applyLocalizedPattern()
: "+geek.toLocalizedPattern());
}
}
|
Output :
Use of applyLocalizedPattern() : MM / dd / yy HH:mm Z
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...