سؤال
GregorianCalendar startDate = new GregorianCalendar(2009, Calendar.JANUARY, 1);
SimpleDateFormat sdf = new SimpleDateFormat("d/m/yyyy");
public void setStart()
{
startDate.setLenient(false);
System.out.println(sdf.format(startDate.getTime()));
}
وعند تشغيل هذا الرمز، وأحصل 1/0/2009. أنا أيضا الحصول على نفس الشيء عندما أقوم بتغيير أشهر. ما هو الخطأ في ذلك وكيف يمكنني إصلاحه؟
المحلول
ووصغيرة 'م' هو لمدة دقيقة في الساعة. يجب عليك استخدام الأحرف الكبيرة "M" بدلا من ذلك.
SimpleDateFormat sdf = new SimpleDateFormat("d/M/yyyy");
وانظر جافادوك SimpleDateFormat
للحصول على مزيد من التفاصيل.
لا تنتمي إلى StackOverflow