How to change TimePicker in NativeScript to show the time in 24-hour format?

巧了我就是萌 提交于 2019-12-08 13:24:49

问题


In NativeScript, there is the TimePicker, which one shows a time, but in 12-hour format. I have a problem, because in my database all of my times are saved in string (in format "23:59").

I canot set hour, e.g. 14.

I have an idea, to convert string with split(':') and changing period AM to PM, but i cannot see any usefull method to do that. Please, help.


回答1:


You can use the native APIs to set the 24-hour format. TimePicker in NativeScript is using UIDatePicker in iOS and android.widget.TimePicker in Android

page.js

   "use strict";
    var application = require("application");
    function onLoaded(args) {
        var page = args.object;
        var tPicker = page.getViewById("tPicker");
        if (application.android) {
            tPicker.android.setIs24HourView(java.lang.Boolean.TRUE);
            tPicker.hour = 23;
            tPicker.minute = 59;
        }
        else if (application.ios) {
            // a bit hacky solution
            // important set the country not the language for locale
            var local = NSLocale.alloc().initWithLocaleIdentifier("NL");
            tPicker.ios.locale = local;
            tPicker.hour = 23;
            tPicker.minute = 59;
        }
    }
    exports.onLoaded = onLoaded;

page.xml

<TimePicker id="tPicker"></TimePicker>


来源:https://stackoverflow.com/questions/38827752/how-to-change-timepicker-in-nativescript-to-show-the-time-in-24-hour-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!