在 Java 中更改日期格式符号
对于日期格式符号,请使用 DateFormatSymbols 类。
首先,使用字符串数组设置工作日
String[] weekDays2 = { "", "monday", "tuesday", "wednesday", "thursday", "friday","saturday", "sunday" };
现在,设置短工作日
DateFormatSymbols mySymbols = new DateFormatSymbols();mySymbols.setShortWeekdays(weekDays2);
获取日期 -
dateFormat = new SimpleDateFormat("EEEE, dd MMM yyyy", mySymbols);System.out.println(dateFormat.format(new Date()));
以下是一个例子 -
示例
import java.text.SimpleDateFormat;输出结果import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.util.Date;
public class Demo {
public static void main(String[] args) {
String[] weekDays1 = { "", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
String[] weekDays2 = { "", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" };
DateFormatSymbols mySymbols = new DateFormatSymbols();
mySymbols.setWeekdays(weekDays1);
mySymbols.setShortWeekdays(weekDays2);
DateFormat dateFormat = new SimpleDateFormat("E, dd MMM yyyy", mySymbols);
System.out.println(dateFormat.format(new Date()));
dateFormat = new SimpleDateFormat("EEEE, dd MMM yyyy", mySymbols);
System.out.println(dateFormat.format(new Date()));
}
}
friday, 22 Nov 2018Friday, 22 Nov 2018
以上是 在 Java 中更改日期格式符号 的全部内容, 来源链接: utcz.com/z/362305.html