Android 如何在整数日期字符串中省略0
我已成功地将日期字符串的格式从Android 如何在整数日期字符串中省略0,android,date,datetime,android-date,android-dateutils,Android,Date,Datetime,Android Date,Android Dateutils,我已成功地将日期字符串的格式从yyyy-MM-dd更改为MM/dd。现在的问题是,如果月和日值均小于10,则格式应为例如2/7,而不是02/07。我该怎么做 这是我的密码: public static String cahngeFormat(String dateTime) { Date date = null; String str = dateTime; DateFormat formatter = new SimpleDateForm
yyyy-MM-dd
更改为MM/dd
。现在的问题是,如果月
和日
值均小于10,则格式应为例如2/7
,而不是02/07
。我该怎么做
这是我的密码:
public static String cahngeFormat(String dateTime) {
Date date = null;
String str = dateTime;
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
date = formatter.parse(str);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, 2);
formatter = new SimpleDateFormat("MM/dd");
str = formatter.format(calendar.getTime());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
我希望这对你有用
我希望这对你有用
我希望这对你有用
我希望这对您有用。将格式从
的“MM/dd”
更改为的“M/d”
以允许单位数输出
formatter = new SimpleDateFormat("M/d");
将格式从
“MM/dd”
更改为“M/d”
,以允许单位数输出
formatter = new SimpleDateFormat("M/d");
将格式从
“MM/dd”
更改为“M/d”
,以允许单位数输出
formatter = new SimpleDateFormat("M/d");
将格式从
“MM/dd”
更改为“M/d”
,以允许单位数输出
formatter = new SimpleDateFormat("M/d");
你是否解决了你的问题?你是否解决了你的问题?你是否解决了你的问题?你是否解决了你的问题?我在寻找是否有其他解决方案,结果发现这与我现在所做的类似。所以我会检查这个问题的解决方案。谢谢。我在寻找是否有其他解决方案,结果发现这与我现在正在做的类似。所以我会检查这个问题的解决方案。谢谢。我在寻找是否有其他解决方案,结果发现这与我现在正在做的类似。所以我会检查这个问题的解决方案。谢谢。我在寻找是否有其他解决方案,结果发现这与我现在正在做的类似。所以我会检查这个问题的解决方案。谢谢