在 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 2018 Friday, 22 Nov 2018
广告