问题
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