Java SimpleDataFormat |集1 更多的文本方法。SimpleDataFormat类:
null
- clone():java。文本SimpleDateFormat。克隆() 创建SimpleDataFormat的副本。
Syntax :public Object clone()Parameters : -------Return : copy of the SimpleDateFormat
JAVA
// 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()); } } |
输出:
Clone : java.text.SimpleDateFormat@a9427c06
- hashCode():java。文本SimpleDateFormat。hashCode() 返回SimpleDataFormat对象的哈希代码值。
Syntax :public int hashCode()Parameters : --------Return : hash code value for the SimpleDateFormat object.
JAVA
// 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()); } } |
输出:
Hash Code : -1455260666
- equals(Object obj):java。文本SimpleDateFormat。等于(对象obj) 比较两个SimpleDataFormat对象
Syntax :public boolean equals(Object obj)Parameters : obj : object to compare withReturn : true, if equal ; else false
JAVA
// 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())); } } |
输出:
Is equal ? : false
- setDateFormatSymbols(DateFormatSymbols新闻符号):java。文本SimpleDateFormat。setDateFormatSymbols(DateFormatSymbols新闻符号) 设置所需日期格式的日期和时间格式符号。
Syntax :public void setDateFormatSymbols(DateFormatSymbols newSymbols)Parameters : newSymbols : new format symbols for data and timeReturn : -------
JAVA
// 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] + "" ); } } } |
输出:
Day1 : SunDay2 : MonDay3 : TueDay4 : WedDay5 : ThuDay6 : FriDay7 : Sat
- getDateFormatSymbols():java。文本SimpleDateFormat。getDateFormatSymbols() 返回日期和时间格式符号的副本。
Syntax :public DateFormatSymbols getDateFormatSymbols()Parameters : -------Return : date and time format symbols.
JAVA
// 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); } } |
输出:
java.text.DateFormatSymbols@f86e64e0Date : 6/24/17 12:49 PM
- ApplyCalizedPattern(String str):java。文本SimpleDateFormat。ApplyCalizedPattern(字符串str) 将给定的本地化字符串模式应用于日期格式。
Syntax :public void applyLocalizedPattern(String str)Parameters : str : string pattern set to new date and time formatReturn : -------
JAVA
// Java Program illustrating // 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 calendar 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()); } } |
输出:
Use of applyLocalizedPattern() : MM / dd / yy HH:mm Z
本文由 莫希特·古普塔(Mohit Gupta_OMG) .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END