如何从新Date()获取日期 [英] how to get only date from new Date()

查看:83
本文介绍了如何从新Date()获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许之前问过这个问题,但令我惊讶的是我搜索了很多没找到任何解决方案

我有这个日期



  var  currentDate =  new  日期< /跨度>(); 





星期二 2015年1月6日 10:40:00 GMT + 0500(巴基斯坦标准时间) )



我怎么才能得到它的完整日期(不是day\time)只有日期(上面一行的粗体部分)

试试这个:

  var  currentDate =  new  日期(); 
var options = {month: short ,year: numeric,day: 2位};
var formattedDate = currentDate.toLocaleDateString( en-US,options);


使用以下代码:



  var  d =  new  日期(); 
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
var formatedDate = curr_date + - + curr_month + - + curr_year;





欲了解更多信息:

http://www.webdevelopersnotes.com/tips/html/javascript_date_and_time.php3 [ ^ ]

谢谢。


Muhamad没有具体的功能来获取日期。

 getDate();< br /> 
getMonth();< br />
getFullYear();



是可用于生成数据的方法。您可以编写一个通用函数并添加脚本(如GlobalFunction.js)并在需要唯一日期撤销功能的每个部分中重复使用。

您可以使用Snesh提到的方法以及if你想要显示名称

然后使用如下,

  var  monthNames = [  1月 二月 三月  April 可以  6月
July 八月 9月 十月 十一月 12月];

document .write( 当前月份为 + monthNames [d.getMonth()]);
// 请记住,january的getMonth()为0!所以我们使用'+1',这里使用数组,因此[0]是1月。
var dayNames = [ 星期一 星期二 星期三 星期四 Friday 星期六
星期日];
var d = new 日期();
document .write(dateNames [d.getDate()] + / + monthNames [d.getMonth()] + /+d.getFullYear())



我希望这会有所帮助。

请回复查询(如果有的话)。

谢谢。


Maybe this question asked before but surprisingly i search a lot didn't find any solution
I have this date

var currentDate = new Date();



Tue Jan 06 2015 10:40:00 GMT+0500 (Pakistan Standard Time)

How can i get only full date from it (not day\time) only Date(bold part of above line)

解决方案

Try this:

var currentDate = new Date();
var options = { month: "short", year: "numeric", day: "2-digit" };
var formattedDate = currentDate.toLocaleDateString("en-US", options);


Use following code:

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
var formatedDate = curr_date + "-" + curr_month + "-" + curr_year ;



For more look at:
http://www.webdevelopersnotes.com/tips/html/javascript_date_and_time.php3[^]
Thanks.


Muhamad there is no specific function to get the date only.

getDate();<br />
getMonth();<br />
getFullYear();


are the methods which you can use to generate your data. You can write a common function and add in the Scripts(like GlobalFunction.js) and reuse in every section where the only date retreival function is needed.
You can use the method Snesh has mentioned and also if you want the Names to be displayed
then use like below,

var monthNames = [ "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December" ];

document.write("The current month is " + monthNames[d.getMonth()]);
//Remember getMonth() for january is 0! so we use '+1', here array is used so [0] is january.
var dayNames = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
    "Sunday"];
var d = new Date();
document.write(dateNames[d.getDate()]+"/"+monthNames[d.getMonth()]+"/"+d.getFullYear())


I hope this helps.
Please post back queries if any.
Thanks.


这篇关于如何从新Date()获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆