Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/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
使用javascript从此格式获取日、月和年_Javascript_Date_Twitter - Fatal编程技术网

使用javascript从此格式获取日、月和年

使用javascript从此格式获取日、月和年,javascript,date,twitter,Javascript,Date,Twitter,我在处理此格式的数据时遇到问题 Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time) 我从twitter上获得这种格式,需要根据我的要求只显示日期和月份。有谁能帮我从这种格式中获取规范吗。或者我们也可以使用与twitter不同的格式 共享您的视图。您可以使用提供的字符串构造Date对象,并按如下方式检索详细信息: HTML 有关日期的更多信息对象检查 希望这对您有所帮助。您可以在javascript中使用,在转换为字符串后拆分日期时间

我在处理此格式的数据时遇到问题

Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)
我从twitter上获得这种格式,需要根据我的要求只显示日期和月份。有谁能帮我从这种格式中获取规范吗。或者我们也可以使用与twitter不同的格式


共享您的视图。

您可以使用提供的字符串构造
Date
对象,并按如下方式检索详细信息:

HTML

有关
日期的更多信息
对象检查

希望这对您有所帮助。

您可以在javascript中使用,在转换为字符串后拆分日期时间。将前两部分用于您的目的

var b = 'I am a JavaScript hacker.'
var temp = new Array();
temp = b.split(' ');
现在,该字符串已拆分为5个字符串,并放置在数组temp中。空间本身也消失了

temp[0] = 'I';
temp[1] = 'am';
temp[2] = 'a';
temp[3] = 'JavaScript';
temp[4] = 'hacker.';

var d=新日期(“2011年12月23日星期五18:37:45 GMT+0530(印度标准时间)”;
警报(d.getDate()+'/'+d.getMonth());

有两个步骤可以解决您的问题:

  • 使用此信息创建
    Date
    对象
  • 从此对象检索年和月
  • 第一步 使用字符串中的信息创建
    Date
    对象

    var dateinfo = new Date("Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)");
    
    步骤2 从新的dateinfo对象检索日期和月份信息

    // Retrieve the day 
    dateinfo.getDay();
    // Retrieve the month
    // Attention here, the month is indexed under 0
    dateinfo.getMonth();
    

    你可以从

    中获取更多信息,阅读:你检查过你的小提琴吗??它显示
    23-12-111
    感谢您的快速响应。它在firefox n chrome中工作。但不在IE上这是我的要求:它应该适用于ie8 n 9。。我正在jfiddle.net上尝试并得到了一个未定义的代码:函数formatDutchDate(){var d=new Date(“Thu-Dec 22 13:36:36+0000 2011”);monthnames=['januari'、'februari'、'maart'、'april'、'mei'、'juni'、'juli'、'augustus'、'mummer'、'oktober'、'sembert'、'sembert'];monthnames=monthnames[d.getMonth()$(“#timeDiv”).text(d.getDate()+“”+monthname)}formatDutchDate();var d=新日期(“Fri Dec 23 13:07:45+0000 2011”);console.log(d);//在iethanks中,用于快速响应的日期无效。它在firefox n chrome中工作。但在IE上不工作。我的要求是:var d=新日期(“Thu Dec 22 13:36:36+0000 2011”);它不在IE上工作,感谢分享JSFIDLE.net链接它的帮助,并将在不久的将来帮助我。请分享您对以上内容的看法,以便在IE上工作。分享您对var d=新日期格式的看法(“Thu Dec 22 13:36:36+0000 2011”);分享您对var d=新日期的看法(“Thu Dec 22 13:36:36+0000 2011”);以及更简洁的声明:)已编辑。
      <html>
      <body>
    
       <script type="text/javascript">
    
        var d = new Date("Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)");
        alert(d.getDate() + '/' + d.getMonth());
    
       </script>
    
      </body>
      </html>
    
    var dateinfo = new Date("Fri Dec 23 2011 18:37:45 GMT+0530 (India Standard Time)");
    
    // Retrieve the day 
    dateinfo.getDay();
    // Retrieve the month
    // Attention here, the month is indexed under 0
    dateinfo.getMonth();