Change time value in div tags with the same class(javascript/jQuery) -


i have index view in mvc 5 project. view uses partial view, partial view included in index this:

<div id="le">     @html.action("_ls", "home") </div> 

after that, index populated code partial view _ls. want change inner html of divs class="mtime". div has time value format hh:mm in utc. want make show user's local time. so, added javascript code before end of body tag in in partial(not in index had initially)

<script type="text/javascript">             $('.mtime').each(function (obj) {                  var date = obj.innerhtml;                 var newdate = new date(date.gettime() + date.gettimezoneoffset() * 60 * 1000);                  var offset = date.gettimezoneoffset() / 60;                 var hours = date.gethours();                  newdate.sethours(hours - offset);                 obj.innerhtml = newdate;              });           </script> 

but value in divs never changes

you can using constructor of date , utc suffix :

$('.mtime').each(function() {     var time = $(this).text();      var date = new date();      date = new date(date.todatestring() + ' ' + time + ' utc');     $(this).text(date.gethours() + ':' + date.getminutes()); }); 

jsfiddle


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -