admin管理员组文章数量:1425717
I am using the following code to display the date in the front-end screen:
<h4> Date :
<script language="JavaScript">
date=Date()
document.write(date)
</script>
</h4>
Here h4
is the tag in CSS.
Here is the code for h4
in CSS file:
It is displaying the date in local machine. But when I deployed the project to the server machine it is not working.
I am using the following code to display the date in the front-end screen:
<h4> Date :
<script language="JavaScript">
date=Date()
document.write(date)
</script>
</h4>
Here h4
is the tag in CSS.
Here is the code for h4
in CSS file:
It is displaying the date in local machine. But when I deployed the project to the server machine it is not working.
Share Improve this question edited Nov 8, 2013 at 14:25 BartoszKP 36k15 gold badges107 silver badges134 bronze badges asked Sep 12, 2011 at 9:19 RajRaj 2,49311 gold badges36 silver badges53 bronze badges 4- @Raj..You mean you want to display date of server using javascript? – Tushar Ahirrao Commented Sep 12, 2011 at 9:22
- @Tushar .. Yes , I want to display server time in front end screen using java script – Raj Commented Sep 12, 2011 at 9:23
- What exactly is your problem? What do you mean by 'it is not working?' If you want to display the time by the server machine, you will have to use a different (server-side) language, such as PHP, because JavaScript is a client-side language. IF you still insist on using javaScript you will have to have a PHP file or something that returns the time on the server, and then get that using JavaScript (AJAX). – Some Guy Commented Sep 12, 2011 at 9:25
- 1 @Raj, I don't understand why you would do that using javascript. Just display the server time in whatever template you use to generate that h4. In erb, for example, that would be something like "<h4>Date: <%= Time.now %></h4>". Obviously, it will be different depending on what framework you are using on the server. In any case, I don't see why you'd do this with javascript. – Ben Lee Commented Sep 12, 2011 at 9:27
1 Answer
Reset to default 3Javascript runs on the client machine (on the browser). new Date()
in javascript gives the date from the client's machine.
To get the date from the server side, you need to pass the date from the server to the client. How you do this depends on the server side technology.
In JSP it would be something like:
<h4> Date : <%= new java.util.Date()%> </h4>
And in PHP:
<h4><?php echo date("d-m-Y"); ?> </h4>
本文标签: javascriptHow to display DateStack Overflow
版权声明:本文标题:javascript - How to display Date? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745419125a2657823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论