0

I'm using the following plugin: http://code.google.com/p/jquery-localtime/wiki/Usage

My elements are rendered on the page with JS so I apply the plugin to the element as follows:

 var format = "dd/MM/yy HH:mm a"; var localise = function () { jQuery(this).text(jQuery.localtime.toLocalTime(jQuery(this).text(), format)); }; jQuery(".localtime").each(localise); 

Problem is this results in the following error:

Uncaught Error: 01/06/12 14:43 PM is not a supported date/time string jquery.localtime-0.5.js:183 

The text being passed to the plugin looks like this "2012-06-01T21:43:15Z" any ideas? Am I calling the plugin incorrectly? Thanks

6
  • var date = jQuery(this).text(); console.log(date);jQuery(this).text(jQuery.localtime.toLocalTime(date, format)); Could you paste what is in the console? Commented Jun 6, 2012 at 4:15
  • jsfiddle.net/xJxxR It works, it means that the problem is the content of your div... Commented Jun 6, 2012 at 4:24
  • Strange, it does work in the jsfiddle which make me think the error is due to the implementation above, perhaps something with the lopping? Commented Jun 6, 2012 at 4:36
  • What the message explicitly say is that you have passed 01/06/12 14:43. The reason could be that you execute it twice... Commented Jun 6, 2012 at 4:38
  • yep that's the issue, it keeps reapplying Commented Jun 6, 2012 at 4:39

1 Answer 1

2

The problem is that the localtime plugin automatically applies the formatting on the page load; so the formatting is applied when the page loads, and again using the code you supply above.

Either prevent the plugin from applying the style by default:

<script type="text/javascript">$.localtime.setFormat({});</script> 

Or remove your code that attempts to re-apply it a second time.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.