Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.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
Javascript 丹麦日期到新日期()_Javascript_Jquery - Fatal编程技术网

Javascript 丹麦日期到新日期()

Javascript 丹麦日期到新日期(),javascript,jquery,Javascript,Jquery,ons okt 01 2014上午10:00 这是2014年10月1日星期三上午10:00(丹麦语) var dt = new Date("ons okt 01 2014 10:00 AM"); 上面的一行给了我“无效日期” 如何在dt变量中获得正确的日期?由于格式本身对日期有效,因此可以正确解析字符串,您应该实现一个函数,将星期和月份的日期从丹麦语转换为英语 function fromDanish(dateString) { //A table whose properties ar

ons okt 01 2014上午10:00

这是2014年10月1日星期三上午10:00(丹麦语)

var dt = new Date("ons okt 01 2014 10:00 AM");
上面的一行给了我“无效日期”


如何在dt变量中获得正确的日期?

由于格式本身对日期有效,因此可以正确解析字符串,您应该实现一个函数,将星期和月份的日期从丹麦语转换为英语

function fromDanish(dateString) {
    //A table whose properties are Danish names for days of week and whose values are English names.
    var daysOfWeek = {'son': 'sun', 'man': 'mon', 'tir': 'tue', 'ons': 'wed', 'tor': 'thu', 'fre': 'fri', 'lor': 'sat'};

    //A table whose properties are Danish names of months and whose values are English names.
    var months = {'jan': 'jan', 'feb': 'feb', 'mar': 'mar', 'apr': 'apr', 'maj': 'may', 'jun': 'jun', 'jul': 'jul', 'aug': 'aug', 'sep': 'sep', 'okt': 'oct', 'nov': 'nov', 'dec': 'dec'};


    var tokens = dateString.split(' '); //Split the Danish string by spaces
    var dow = tokens[0]; //This is the Danish day of week
    var month = tokens[1]; // and this is the Danish month 

    tokens[0] = daysOfWeek[dow]; //Get the English day of week from the table
    tokens[1] = months[month]; //Get the English month from the table
    var english_date = tokens.join(' '); //Join all tokens again
    return new Date(english_date); //Now Date() constructor knows how to parse the date string
}

由于格式本身对Date有效,因此可以正确解析字符串,因此应该实现一个函数,将周和月的日期从丹麦语转换为英语

function fromDanish(dateString) {
    //A table whose properties are Danish names for days of week and whose values are English names.
    var daysOfWeek = {'son': 'sun', 'man': 'mon', 'tir': 'tue', 'ons': 'wed', 'tor': 'thu', 'fre': 'fri', 'lor': 'sat'};

    //A table whose properties are Danish names of months and whose values are English names.
    var months = {'jan': 'jan', 'feb': 'feb', 'mar': 'mar', 'apr': 'apr', 'maj': 'may', 'jun': 'jun', 'jul': 'jul', 'aug': 'aug', 'sep': 'sep', 'okt': 'oct', 'nov': 'nov', 'dec': 'dec'};


    var tokens = dateString.split(' '); //Split the Danish string by spaces
    var dow = tokens[0]; //This is the Danish day of week
    var month = tokens[1]; // and this is the Danish month 

    tokens[0] = daysOfWeek[dow]; //Get the English day of week from the table
    tokens[1] = months[month]; //Get the English month from the table
    var english_date = tokens.join(' '); //Join all tokens again
    return new Date(english_date); //Now Date() constructor knows how to parse the date string
}

由于格式本身对Date有效,因此可以正确解析字符串,因此应该实现一个函数,将周和月的日期从丹麦语转换为英语

function fromDanish(dateString) {
    //A table whose properties are Danish names for days of week and whose values are English names.
    var daysOfWeek = {'son': 'sun', 'man': 'mon', 'tir': 'tue', 'ons': 'wed', 'tor': 'thu', 'fre': 'fri', 'lor': 'sat'};

    //A table whose properties are Danish names of months and whose values are English names.
    var months = {'jan': 'jan', 'feb': 'feb', 'mar': 'mar', 'apr': 'apr', 'maj': 'may', 'jun': 'jun', 'jul': 'jul', 'aug': 'aug', 'sep': 'sep', 'okt': 'oct', 'nov': 'nov', 'dec': 'dec'};


    var tokens = dateString.split(' '); //Split the Danish string by spaces
    var dow = tokens[0]; //This is the Danish day of week
    var month = tokens[1]; // and this is the Danish month 

    tokens[0] = daysOfWeek[dow]; //Get the English day of week from the table
    tokens[1] = months[month]; //Get the English month from the table
    var english_date = tokens.join(' '); //Join all tokens again
    return new Date(english_date); //Now Date() constructor knows how to parse the date string
}

由于格式本身对Date有效,因此可以正确解析字符串,因此应该实现一个函数,将周和月的日期从丹麦语转换为英语

function fromDanish(dateString) {
    //A table whose properties are Danish names for days of week and whose values are English names.
    var daysOfWeek = {'son': 'sun', 'man': 'mon', 'tir': 'tue', 'ons': 'wed', 'tor': 'thu', 'fre': 'fri', 'lor': 'sat'};

    //A table whose properties are Danish names of months and whose values are English names.
    var months = {'jan': 'jan', 'feb': 'feb', 'mar': 'mar', 'apr': 'apr', 'maj': 'may', 'jun': 'jun', 'jul': 'jul', 'aug': 'aug', 'sep': 'sep', 'okt': 'oct', 'nov': 'nov', 'dec': 'dec'};


    var tokens = dateString.split(' '); //Split the Danish string by spaces
    var dow = tokens[0]; //This is the Danish day of week
    var month = tokens[1]; // and this is the Danish month 

    tokens[0] = daysOfWeek[dow]; //Get the English day of week from the table
    tokens[1] = months[month]; //Get the English month from the table
    var english_date = tokens.join(' '); //Join all tokens again
    return new Date(english_date); //Now Date() constructor knows how to parse the date string
}

我建议使用日期库:


我建议使用日期库:


我建议使用日期库:


我建议使用日期库:


Globalize.js是解决我的问题的好方法吗?你对此有什么想法吗?应该是因为jQuery团队支持它,但我对它不太熟悉。Globalize.js是解决我问题的一个好选择吗?你对此有什么想法吗?应该是因为jQuery团队支持它,但我对它不太熟悉。Globalize.js是解决我问题的一个好选择吗?你对此有什么想法吗?应该是因为jQuery团队支持它,但我对它不太熟悉。Globalize.js是解决我问题的一个好选择吗?你对此有什么想法吗?应该是因为jQuery团队支持它,但我对它不太熟悉。谢谢Claudix。我正在寻找一个通用的解决方案。丹麦字符串只是一个例子。我正在寻找除英语字符串以外的任何字符串。这个答案可以,但在拆分日期字符串之前,我会包含一个
.toLowerCase()
,因为日期可能包含大写字母。谢谢Claudix。我正在寻找一个通用的解决方案。丹麦字符串只是一个例子。我正在寻找除英语字符串以外的任何字符串。这个答案可以,但在拆分日期字符串之前,我会包含一个
.toLowerCase()
,因为日期可能包含大写字母。谢谢Claudix。我正在寻找一个通用的解决方案。丹麦字符串只是一个例子。我正在寻找除英语字符串以外的任何字符串。这个答案可以,但在拆分日期字符串之前,我会包含一个
.toLowerCase()
,因为日期可能包含大写字母。谢谢Claudix。我正在寻找一个通用的解决方案。丹麦字符串只是一个例子。我正在寻找除英语字符串以外的任何字符串。这个答案可以,但在拆分日期字符串之前,我会包含一个
.toLowerCase()
,因为日期可能包含大写字母。