[英]Changing the time and date format
I would like to learn how can I run and see the display in this code : 我想学习如何运行并查看此代码中的显示:
var now = new Date();
now.format("m/dd/yy");
// Returns, e.g., 6/09/07
// Can also be used as a standalone function
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM
Thanks. 谢谢。
Be sure that you download the plugin and include it somewhere either in the head of your page, or beneath the body like this 确保下载插件,并将其包含在页面顶部或正文下方的某个位置
<script type='text/javascript' src='pathToFile.js'></script>
Next, if you're using a modern browser, you should have a debugger console in which you can test code. 接下来,如果您使用的是现代浏览器,则应该有一个调试器控制台,您可以在其中测试代码。 If you're using Firefox, take a look at firebug , and if you're using Chrome, you already have one, just hit CTRL+SHIFT+J to pull up the console.
如果您使用的是Firefox,请查看firebug ,如果您使用的是Chrome,则已经拥有一个,只需按CTRL + SHIFT + J即可调出控制台。 Once inside of the console, you can enter the commands as you entered them above and see the results.
进入控制台后,您可以按上面输入的命令输入命令并查看结果。 I hope this helps!
我希望这有帮助!
Back in the old days... 回到过去
To view the outcome of your code, you'd traditionally need to make an HTML page and stick that into the <script type="javascript">...</script>
section of your code. 要查看代码的结果,传统上,您需要制作一个HTML页面并将其粘贴到代码的
<script type="javascript">...</script>
部分。
Nowadays! 如今!
Nowadays, you can do it right online! 如今,您可以在线上进行操作! Try plugging your code into this: http://writecodeonline.com/javascript/
尝试将您的代码插入此文件: http : //writecodeonline.com/javascript/
No output? 没有输出?
you can use document.write( now );
您可以使用
document.write( now );
to display your variable now
to the screen. now
将您的变量显示在屏幕上。
Still no output? 仍然没有输出?
I believe that dateFormat
and format
will give you errors as JavaScript doesn't know what this is (unless you wrote these methods in your code). 我相信
dateFormat
和format
会给您带来错误,因为JavaScript不知道这是什么(除非您在代码中编写了这些方法)。 See this StackOverflow question for some resources with formatting Javascript Dates. 有关格式化Javascript日期的某些资源, 请参见StackOverflow问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.