我有以下代码:
package com.company.customer;
import java.util.*;
import java.text.*;
import java.io.*;
public class DateSample {
private TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
private SimpleDateFormat sdfDate = new SimpleDateFormat();
private Date inputDate;
private String dateInString = "2015-07-15";
private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
public void datePrint() {
sdfDate.setTimeZone(GMT_TIMEZONE);
sdfDate.applyPattern("EE-ddMMM");
try {
inputDate = formatter.parse(dateInString);
} catch (Exception e) {
System.out.println("populateTabDates: ParseException");
}
String formatResults = sdfDate.format(inputDate);
// Modify the return to cut down the weekday: Fri-20Aug => Fr-20Aug
formatResults = formatResults.substring(0, 2) + formatResults.substring(3);
System.out.println(formatResults); …Run Code Online (Sandbox Code Playgroud)