Getting global (UTC or GMT) time in angularjs and not local time
NickName:Baek Ryun Ask DateTime:2016-12-01T09:44:37

Getting global (UTC or GMT) time in angularjs and not local time

Is there any way to do this in angular js or just javascript? Getting a time that does not depend on the local date of the PC? The only solution I could think of was to constantly make requests to the back-end so it would use the server's time and not the client-side local time but it's not really a solution as it would require to constantly make requests, which clearly sucks as it's a brute force method that doesn't really yield the desired result since the requests obviously have delay.

Copyright Notice:Content Author:「Baek Ryun」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40901290/getting-global-utc-or-gmt-time-in-angularjs-and-not-local-time

Answers
Ali Kareem Raja 2016-12-01T07:18:24

//converts local time to UTC (Universal Time)\nfunction toUTC(/*Date*/date) {\n return Date.UTC(\n date.getFullYear()\n , date.getMonth()\n , date.getDate()\n , date.getHours()\n , date.getMinutes()\n , date.getSeconds()\n , date.getMilliseconds()\n );\n} //toUTC()\n\n\nThis function will give you the unix epoch ticks in UTC (thanks to: http://blog.davidjs.com/2011/05/convert-local-time-to-utc-time-in-javascript/)\n\nIf you need to display this in a user friendly way please consult the reference: http://www.w3schools.com/jsref/jsref_obj_date.asp\n\nGood luck!",


More about “Getting global (UTC or GMT) time in angularjs and not local time” related questions

Converting local time into UTC time in angularjs

I am using var date= new Date(); in my controller to get current local time. I am getting the output like this- var date=Mon Aug 03 2015 07:56:55 GMT +0530(India Standard Time) but i need UTC ...

Show Detail

Getting global (UTC or GMT) time in angularjs and not local time

Is there any way to do this in angular js or just javascript? Getting a time that does not depend on the local date of the PC? The only solution I could think of was to constantly make requests to ...

Show Detail

PHP 5.2.17: convert local time to GMT and GMT to local time

In my application, I just want to convert a local time to GMT and GMT to local time. I got the following two methods to do so. function GmtTimeToLocalTime($date) { $gmt_time = date("Y-m-d H:i:...

Show Detail

Conversion of Local Time to GMT/UTC, and back GMT/UTC to Local Time in C++

The problem of conversion from GMT/UTC to local time in C++ is tricky because of daylight saving. To solve the daylight saving problem there must be a table for every country and zone, since daylight

Show Detail

convert time GMT to UTC

I am trying to convert a time that I receive with GMT time but I render details by time format using strptime. from datetime import tzinfo, timedelta, datetime ZERO = timedelta(0) class FixedOffset(

Show Detail

Convert UTC/GMT time to local time

We are developing a C# application for a web-service client. This will run on Windows XP PC's. One of the fields returned by the web service is a DateTime field. The server returns a field in GMT ...

Show Detail

Convert UTC/GMT time to local time

We are developing a C# application for a web-service client. This will run on Windows XP PC's. One of the fields returned by the web service is a DateTime field. The server returns a field in GMT ...

Show Detail

Convert UTC/GMT time to local time

We are developing a C# application for a web-service client. This will run on Windows XP PC's. One of the fields returned by the web service is a DateTime field. The server returns a field in GMT ...

Show Detail

How do I convert local time zone to utc and utc local time zone?

I want to store UTC time in DB (yyyy-mm-dd or dd-mm-yyyy) I want to convert local time zone to UTC and store it in DB I tried in different ways but that is not working properly. Below is my code...

Show Detail

GMT time and UTC time not same

As far as I understood, UTC and GMT time should be same, even in daylight saving time applied. So if you google "Current UTC time" and "Current GMT time", they both give you exact same number. Ho...

Show Detail