打字稿-从字符串中提取值

时间:2018-08-23 22:45:22

标签: angular typescript

有没有一种衬里来获得该值:

1536634800

出于

Timestamp(seconds=1536634800, nanoseconds=0)

3 个答案:

答案 0 :(得分:2)

使用此正则表达式模式:

#include <stdio.h>
#include <stdint.h>

typedef struct s{
    uint8_t a[1];
    uint16_t b;
    uint8_t c[1];
}s_t;

int main()
{
    printf("size = %d", sizeof(s_t));
    return 0;
}

答案 1 :(得分:1)

start_test --performance test/performance/sungeun/assign.chpl

答案 2 :(得分:0)

要获取字符串中的时间,可以执行以下操作。基本上,正在做的是使用正则表达式匹配在一起的{10}个数字。

TS

user={'name':'test','age':'23','place':'london'}.

结果将是 let time = 'Timestamp(seconds=1536634800, nanoseconds=0)'.match( /[0-9]{10}/g ); //Convert it into an actual date. Remeber to add a +1 to months since they start on zero 0. let parsedTime = new Date(parseInt(this.time[0])); //Store the formated date let fomarmatedDate = this.formatDate(this.parseTime); formatDate(time: Date) : String { //In the mm we check if it's less than 9 because if it is your date will look like m/dd/yy // so we do some ternary to check the number and get the mm let mm = time.getMonth()+1<9 ? `0${time.getMonth()+1}` : time.getMonth()+1; let dd = time.getDate(); let yyyy = time.getFullYear(); let date = `${mm}/${dd}/${yyyy}`; return date }

您可以使代码更短。我只是这样做,所以您可以看到它的工作原理以及我在做什么。

要了解有关.match的更多信息,请访问此页面https://www.w3schools.com/jsref/jsref_match.asp

您可以使用此工具来构建正则表达式https://regexr.com/