小编Met*_*ean的帖子

Date.prototype.toLocaleTimeString() 中的hourCycle 选项有什么区别

toLocaleTimeString() 的 MDN 文档指出hourCyclehc选项有四个可能的值:"h11", "h12", "h23", & "h24"

两个可能的值让我觉得非常明显(即"h12""h24"),但另外两个,我不知道它们做什么,我的duckduckfoo/googlefoo 失败了!

什么是"h11""h23"代表值?

我最好的猜测是,他们是某种类型的0VS1的推导"h12""h24",但基础日期戳仍然相同,并且记录的值相同,所以如果是这样,区别在哪里?

这应该在MDN 的 toLocalTimeString 页面ECMAScript 的 toLocalTimeString 页面上记录或至少链接到,但事实并非如此。它也确实让我觉得应该很容易弄清楚,但我没有看到差异,它现在在我的皮肤下爬行!

const now = new Date();
console.log('hourCycle: h11', now.toLocaleTimeString('en-US', { hourCycle: 'h11' }))
console.log('hourCycle: h12', now.toLocaleTimeString('en-US', { hourCycle: 'h12' }))
console.log('hourCycle: h23', now.toLocaleTimeString('en-US', { hourCycle: 'h23' }))
console.log('hourCycle: h24', now.toLocaleTimeString('en-US', { hourCycle: 'h24' …
Run Code Online (Sandbox Code Playgroud)

javascript datetime specifications

7
推荐指数
2
解决办法
2125
查看次数

用正则表达式比较两个字符串的替代方法是什么

我想比较两个字符串,它们之间有不同的分隔符。

例子

String s1 = "ZZ E5 - Pirates of carribean";
String s2 = "ZZ E5 : Pirates of carribean"; 
Run Code Online (Sandbox Code Playgroud)

我想比较两个字符串是否相等。

我试过在 Java 中使用正则表达式来解决这个问题,

        String pattern = "(.*)[:-](.*)";
        // Create a Pattern object
        Pattern r = Pattern.compile(pattern);

        // Now create matcher object.
        Matcher m = r.matcher(s1);
        Matcher m1 = r.matcher(s2);

        if (m1.find()&&m.find()) {
            System.out.println("Found value: " + m.group(1));
            System.out.println("Found value: " + m.group(2));
            System.out.println("Found value: " + m1.group(1));
            System.out.println("Found value: " + m1.group(2));

            System.out.println(m.group(1).contentEquals(m1.group(1)));
            System.out.println(m.group(2).contentEquals(m1.group(2)));
        } else {
            System.out.println("NO MATCH"); …
Run Code Online (Sandbox Code Playgroud)

java regex string

1
推荐指数
1
解决办法
1801
查看次数

标签 统计

datetime ×1

java ×1

javascript ×1

regex ×1

specifications ×1

string ×1