如何更改NativeScript中的TimePicker以24小时格式显示时间? [英] How to change TimePicker in NativeScript to show the time in 24-hour format?

查看:90
本文介绍了如何更改NativeScript中的TimePicker以24小时格式显示时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NativeScript中,有一个TimePicker,它显示一个时间,但格式为12小时.我有一个问题,因为我所有的时间都保存在字符串中(格式为"23:59").

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").

我无法设定小时,例如14.

I canot set hour, e.g. 14.

我有一个主意,可以将split(':')转换为字符串并将AM更改为PM,但是我看不到任何有用的方法来实现.请帮助.

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.

推荐答案

您可以使用本机API设置24小时格式. NativeScript中的TimePicker在iOS中使用 UIDatePicker android.widget.TimePicker (在Android中

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>

这篇关于如何更改NativeScript中的TimePicker以24小时格式显示时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆