简体   繁体   English

如何更改android时间选择器对话框的输出?

[英]How to change android time picker dialogue output?

I am using a time picker dialogue in my app , so the problem is simple ., I want the time in the format 07:00 AM . 我在我的应用程序中使用了时间选择器对话框,所以问题很简单,我希望将时间设置为07:00 AM。 Here is my code and I got output as 7:00 AM . 这是我的代码,我在7:00 AM输出。 Thanks in advance.. 提前致谢..

private TimePickerDialog.OnTimeSetListener TimePickerListener = new TimePickerDialog.OnTimeSetListener() {

    // while dialog box is closed, below method is called.
    public void onTimeSet(TimePicker view, int hour, int minute) {

        mCalen.set(Calendar.HOUR_OF_DAY, hour);
        mCalen.set(Calendar.MINUTE, minute);

        int hour12format = mCalen.get(Calendar.HOUR);
        hourOfDay = mCalen.get(Calendar.HOUR_OF_DAY);
        minute = mCalen.get(Calendar.MINUTE);
        ampm = mCalen.get(Calendar.AM_PM);
        String ampmStr = (ampm == 0) ? "AM" : "PM";
        // Set the Time String in Button
        if(flag==111)
             from.setText(hour12format + ":" + minute + " "+ ampmStr);
        else if(flag==222)
             to.setText(hour12format + ":" + minute + " "+ ampmStr);
    }
};

My suggestion. 我的建议。

private TimePickerDialog.OnTimeSetListener TimePickerListener = new TimePickerDialog.OnTimeSetListener() {

// while dialog box is closed, below method is called.
public void onTimeSet(TimePicker view, int hour, int minute) {

    mCalen.set(Calendar.HOUR_OF_DAY, hour);
    mCalen.set(Calendar.MINUTE, minute);

    int hour12format = mCalen.get(Calendar.HOUR);
    hourOfDay = mCalen.get(Calendar.HOUR_OF_DAY);
    minute = mCalen.get(Calendar.MINUTE);
    ampm = mCalen.get(Calendar.AM_PM);
    String ampmStr = (ampm == 0) ? "AM" : "PM";

    //Format Date and/or Time see more: http://developer.android.com/reference/java/text/SimpleDateFormat.html
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm aaa");
    String strDateFormat = "";
    try {
        strDateFormat = sdf.format(mCalen..getTime());
    } catch (Exception e) {
        // ...
    }

    // Set the Time String in Button
    if(flag==111)
         from.setText(strDateFormat);
    else if(flag==222)
         to.setText(strDateFormat);
}

}; };

Edit: 编辑:

Sorry the correct mask "HH:mm aaa" 对不起,正确的口罩“ HH:mm aaa”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中更改时间选择器字体颜色? - How to Change Time Picker Font Color in Android? 将时间选择器对话框的时间设置为所选时间 - Set the time of time picker dialogue to the selected time 更改时间选择器的主题-Android - Change Theme of Time Picker - Android 如何更改Android中时间选择器的钟面和钟针颜色 - How to change color of the clock face and clock hand of time picker in Android 如何更改 Android 中的材料日期和时间选择器背景颜色? - How to change the Material Date & Time Picker background color in Android? 在Android中按位置更改“时间选择器”中的时间 - change time from Time picker by Location in android 更改时间选择器的文本颜色 [android] - change the text color of Time Picker [android] 如何在Android中创建完全自定义的Dialogue / Popup(更改叠加颜色和对话窗口布局) - How to create a completely custom Dialogue/Popup in Android (change overlay colour and dialogue window layout) android中进度对话时限 - Time limit for progress dialogue in android 如何更改android小部件选择对话框中显示的图像? - How to change the image displayed in the android widget selection dialogue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM