【问题标题】:How to separate minute tens and ones digit如何区分分钟的十位和个位
【发布时间】:2015-03-12 00:07:42
【问题描述】:

我目前已经编写了这段代码:

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, 12:34,这将输出。我正在尝试实现 1 2 3 4 的输出。我应该如何提取和分离小时和分钟的个位和十位?

【问题讨论】:

    标签: pebble-sdk cloudpebble pebble-js


    【解决方案1】:

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

    我会尝试这样的事情:

    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'
    });
    

    作为警告,我尚未测试此代码的运行,它可能需要进行一些小的调整才能使其正常工作,但它应该全面了解您需要以您想要的方式格式化文本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 2016-04-25
      相关资源
      最近更新 更多