var app = angular.module('momentTest', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
var mn = moment(); // Gets the tims now
// Moment objects are mutable and every call tends to change the
// underlying datastructure, so use clone to create the then object.
var mt = mn.clone().subtract(1, 'days');
$scope.now = mn.format("YYYY-MM-DD hh:mm:ss");
$scope.nowUtc = mn.format("YYYY-MM-DD hh:mm:ss");
$scope.then = mt.format("YYYY-MM-DD hh:mm:ss");
$scope.thenUtc = mt.utc().format("YYYY-MM-DD hh:mm:ss");
// to instantiate a moment object using UTC time from SQL Server
// use the moment.utc method.
var ssu = moment.utc('2018-08-15T08:53:04');
$scope.sqlServerUtc = ssu.format("YYYY-MM-DD hh:mm:ss");
$scope.sqlServerLocal = ssu.local().format("YYYY-MM-DD hh:mm:ss");
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<script data-require="moment.js@2.14.1" data-semver="2.14.1" src="https://npmcdn.com/moment@2.14.1"></script>
<script src="app.js"></script>
</head>
<body ng-app="momentTest">
<div ng-controller="MainCtrl">
<h1>Momentjs UTC Examples</h1>
<p>
Look in the app.js file to see how these date/time stamps were created.
</p>
<p>
<b>Now:</b> {{now}}<br/>
<b>Now UTC:</b> {{nowUtc}}
</p>
<p>
<b>Then:</b> {{then}} <br/>
<b>Then UTC:</b> {{thenUtc}}
</p>
<h2>Conversion from SQL Server datetime format</h2>
<p>
The following examples convert from the MS SQL Server datetime string
format. This string is '2018-08-15T08:53:04'
</p>
<p>
<b>SQL Server UTC:</b> {{sqlServerUtc}} <br/>
<b>SQL Server Local:</b> {{sqlServerLocal}}
</p>
</div>
</body>
</html>
/* Put your css in here */
# UTC example
In the log viewer app the loggedDateTime is stored in the database in UTC
format. I need a way to filter the log display on time, and display
this time in local time to avoid confusion.