How to display localtime in JQuery and AngularJS

How to display the localtime in JQuery and AngularJS?

I have tried the jquery.localtime-0.5.js but it does not work at all.

Error 1: Cannot read property 'setFormat' of undefined
Error 2: Cannot read property 'getFormat' of undefined
LVL 1
chuang4630Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chuang4630Author Commented:
I have followed the example:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.localtime-0.5.js"></script>
<script type="text/javascript">$.localtime.setFormat("yyyy-MM-dd HH:mm");</script>


<span class="localtime">2010-12-12 19:27:00Z</span>

But it does not work
0
Rainer JeschorCommented:
Hi,
not sure but at least you are using very old versions both of jQuery and jQuery.localtime.

It works both locally and on jsFiddle using the latest jQuery 1.11 and the latest jquery.localtime:
http://jsfiddle.net/EE_RainerJ/oeuugL8r/

But it is very picky on where you add the script src (head / body).

And second: is your site using HTTPS ? Because you load jquery from Google site using HTTP - this might be also an issue.

HTH
Rainer
0
BigRatCommented:
You use a Javascript Date object and format it with a filter.

https://docs.angularjs.org/api/ng/filter/date

and if you don't specify a time zone the zone of the browser will be used (which corresponds to local time)

You usually have to set this up in the controller :-

http://www.aspsnippets.com/Articles/AngularJS-Get-and-display-Current-Date-and-Time.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.