Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div class="container">
  <br />
  <form>
  <!-- emulating server value of "2015-03-04 21:00:00 UTC" -->
    
    <div class="form-group">
      <label for="event_start">Undesired Output (local time)</label>
      <input type="text" class="form-control" id="event_start" value="2015-03-04 21:00:00 UTC">
    </div>
    <div class="form-group">
      <label for="event_start2">Desired Output (UTC time)</label>
      <input type="text" class="form-control" id="event_start2" value="2015-03-04 21:00:00 UTC">
    </div>
    
  </form>
  </div>
</body>
</html>
 
date = moment($("#event_start").val()); // date time value from database
$("#event_start").val(date.format('YYYY-MM-DD HH:mm')); // formatting the date time
$("#event_start2").val(date.utc().format('YYYY-MM-DD HH:mm')); // formatting the date time
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers