开发者

Date not getting displayed

I have a开发者_运维知识库 html page wherein i want to the date. If I open the html file with any browser it's displaying correctly. But when I put it in server it's not working.

My script goes like this

<P>Payment is due on <script type="text/javascript">
<!--
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
//-->
</script>.</P>


Maybe it's the semi-colons at the end of each line that matters. Also you don't need to include the "<!-- //-->" in javascript as it is now ignored (Don't expect netscape users now). It might be a problem (I guess) if the browser parse it as if it is comments so your code didn't work.

Following code is tested on jsfiddle.

<script type="text/javascript">
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.write(month + "/" + day + "/" + year);
</script>


Just one line code:

var today = new Date().toLocaleFormat("%m/%e/%Y"); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜