开发者

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, 20开发者_开发知识库07, 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. 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.

Nowadays!

Nowadays, you can do it right online! Try plugging your code into this: http://writecodeonline.com/javascript/

No output?

you can use document.write( now ); to display your variable now to the screen.

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). See this StackOverflow question for some resources with formatting Javascript Dates.


If you're looking for a library that makes working with dates easier, I recommend Datejs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜