Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pebble sdk 如何将分钟十和一位数分开_Pebble Sdk_Cloudpebble_Pebble Js - Fatal编程技术网

Pebble sdk 如何将分钟十和一位数分开

Pebble sdk 如何将分钟十和一位数分开,pebble-sdk,cloudpebble,pebble-js,Pebble Sdk,Cloudpebble,Pebble Js,我目前编写了以下代码: var timeText = new UI.TimeText({ position: new Vector2(0, 25), size: new Vector2(144, 30), text: "%H:%M", font: 'bitham-42-bold', color: 'black', textAlign: 'center' }); 如果时间是12:34,这将输出。我正在努力实现1234的输出。我应该如何提取和分离小时和分钟的1和10位?您需要先将时间存储到它自己的

我目前编写了以下代码:

var timeText = new UI.TimeText({
position: new Vector2(0, 25),
size: new Vector2(144, 30),
text: "%H:%M",
font: 'bitham-42-bold',
color: 'black',
textAlign: 'center'
});

如果时间是12:34,这将输出。我正在努力实现1234的输出。我应该如何提取和分离小时和分钟的1和10位?

您需要先将时间存储到它自己的变量中,然后从中分离出来

我想试试这样的东西:

var timeString = "%H%M";
然后,您有两个选项,这是如何使用
for
循环来实现的:

var timeT = "";
for(int i = 0; i < timeString.length; i++){
    if(i > 0) 
        timeT+= " ";

    timeT += timeString.CharAt(i);
}

var timeText = new UI.TimeText({
    position: new Vector2(0, 25),
    size: new Vector2(144, 30),
    text: timeT,
    font: 'bitham-42-bold',
    color: 'black',
    textAlign: 'center'
});
作为一个警告,我还没有测试这段代码的运行,它可能需要一些小的调整,以使其工作,但它应该是全面的,你需要什么格式的文本你想要的方式

var timeText = new UI.TimeText({
    position: new Vector2(0, 25),
    size: new Vector2(144, 30),
    text: timeString.CharAt(0) + " " + timeString.CharAt(1) + " " + timeString.CharAt(2) + " " + timeString.CharAt(3);
    font: 'bitham-42-bold',
    color: 'black',
    textAlign: 'center'
});