javascript - How to display Date? - Stack Overflow

I am using the following code to display the date in the front-end screen:<h4> Date :<script l

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
Add a ment  | 

1 Answer 1

Reset to default 3

Javascript 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745419126a4626887.html

相关推荐

  • javascript - How to display Date? - Stack Overflow

    I am using the following code to display the date in the front-end screen:<h4> Date :<script l

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信