gpt4 book ai didi

java - Android Datepicker 在格式化时返回奇怪的值

转载 作者:行者123 更新时间:2023-12-01 19:37:44 25 4
gpt4 key购买 nike

我的日期选择器有问题。当我选择日期时。我想将其解析为 d/m/yy 格式。不幸的是它不能正常工作。
返回的字符串类似于

7/67/89

 private SimpleDateFormat sdf = new SimpleDateFormat("d/m/yy");
public void openDataPicker(View view) {
clickedTextEdit = (TextInputEditText) view;
final Calendar cldr = Calendar.getInstance();
int day = cldr.get(Calendar.DAY_OF_MONTH);
int month = cldr.get(Calendar.MONTH);
int year = cldr.get(Calendar.YEAR);

picker = new DatePickerDialog(CreateProfileActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar c = Calendar.getInstance();
c.set(year, monthOfYear, dayOfMonth);
clickedTextEdit.setText(sdf.format(c.getTime()));
}
}, year, month, day);
picker.show();
}

最佳答案

使用正确的格式。

看这个:


"EEE, d MMM yyyy HH:mm:ss Z" // Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ" // 010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" // 2001-07-04T12:08:56.235-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" // 2001-07-04T12:08:56.235-07:00
"YYYY-'W'ww-u" // 2001-W27-3
"yyyy.MM.dd G 'at' HH:mm:ss z" // 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy" // Wed, Jul 4, '01
"h:mm a" // 12:08 PM
"hh 'o''clock' a, zzzz" // 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" // 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa" // 02001.July.04 AD 12:08 PM``

关于java - Android Datepicker 在格式化时返回奇怪的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56795272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com