Here, I have string date_time as "2022-10-27T01:35:48.354z" , the same and time i need to initialise as date time object with same and time as in given string.
I have tried
new Date() in javascript,
format.parse, format.format in suitescript,
moment library file too, but still could not get solution.
Please help me on this. I will be thankful.
I'm trying to convert a local time event - 8AM - stored on db - to the client's local time in another country.
Event in Mexico City 8AM to Paris, for example.
I don't know JS but I can identify the local time in the client machine with this:
<script>
function myFunction() {
var d = new Date();
var n = d.getTimezoneOffset();
}
</script>
Now I trying to send this value to CLASSIC ASP - back to server.
To do this I trying to create a link to send the information in a query string.
www.domain.com/login.asp?utc=XXXX
THen I can get the UTC time from client and convert with Classic ASP (I have better knowledge of Classic ASP)
Another easy way is to create a SESSION in JS - but I don't know how and I it's works with CLassic ASP sessions too.
Any idea?
tks!
Daniel
I would recommend using browser cookies and Classic ASP's Response.Cookies collection to do this. The Javascript to do this is pretty simple:
// get the current date from the user's local machine
var now = new Date();
/*
The getTimezoneOffset() function returns the timezone offset in minutes.
If you want to convert dates from UTC to the user's local time
based on the timezone the user has set on their machine you need to
multiple the result by -1.
This method does have the caveat that it assumes the user has set
their local machine's timezone information correctly.
*/
var offset = -now.getTimezoneOffset();
// write a cookie to the user's browser with the offset
document.cookie = "offset_to_utc="+offset
You could check to see if the cookie already exists rather than checking the user's timezone each time; however, if the user changes their timezone information during the same session, the change would not be reflected.
On the next page load and any page loads in the same browser session, you can retrieve the cookie you just set on the server side using Response.Cookies:
Dim OffsetToUTC
OffsetToUTC = Response.Cookies("offset_to_utc").Value
'Since cookies can be modified by users, it is a good idea to check the type
'of the data retrieved and convert it to an integer only if it is numeric.
If IsNumeric(OffsetToUTC) Then
OffsetToUTC = CInt(OffsetToUTC)
Else
OffsetToUTC = 0
End If
To convert a date in the database stored in UTC to the user's local time would look something like this:
Dim DBDate
DBDate = '<Replace with your code to get the date from the database>'
Response.Write(DateAdd("n", OffsetToUTC, DBDate))
I am running into an issue where CRM doesn't appear to be treating the DateTime correctly with OData. Specifically, we are trying to create a custom record called new_vod with a start and end time (and a few other attributes that I have removed from here for simplicity) using a JavaScript call to the CrmRestKit. When the user performing this function is not in the same time zone as the server, the time is incorrect by whatever the offset between the server and the user happens to be.
For example, if my CRM user is in Mountain Time and the Server is in Eastern Time, the Start Time will be 2 hours from now (even though it should be now) when looking at the newly created record in CRM. The user's computer's timezone doesn't seem to have any impact on the result. (I'm comparing the "new_starttime" against the "Created On" time to confirm I'm not just viewing the data wrong, and the created on time is 2 hours before the start time in this scenario).
Here is the relevant snippet:
var startTime = new Date();
//Add 90 minutes to the current date/time
var endTime = new Date();
endTime.setMinutes(startTime.getMinutes() + 90);
//Create a cvt_VOD record
var newVOD = {
'new_starttime': startTime,
'new_endtime': endTime
};
var createdVOD = CrmRestKit.Create('new_vod', newVOD)
...
I noticed that when I debug the create of the new_vod record in a pre-stage plugin, the "conversion" to UTC has already occurred incorrectly, so it leads me to believe that the Rest Call itself isn't right.
Can anyone shed any light on why this would be happening?
FYI, We're on CRM 2015 on-premise.
Try this working solution by Somesh:
https://community.dynamics.com/crm/b/dynamicscrmbestpractices/archive/2014/12/04/crm-timezone-issue-using-javascript
Hello I'm having trouble how can I overcome this problem I search some articles but some examples provided is in PHP. As my title above how can I get the Date and Time from the PC2(Server side where I publish my project) (example of date and time is 8/12/2016 4:40 PM) -- and the current time of my PC1(client side who use the project) (example of date and time is 8/10/2016 5:00). What I want is, I want to display the server side time into one of my label in a view. And even I manipulate / change the PC1 date and time setting the label don't affect / change because it came from the PC2 time. I tried to use Datetime.now() and try to change the setting time from the PC1 and my label date also change after I refresh the page.
It seems you are working with Asp.net-Mvc, you want to display your server time to client browser. If you are using Razor template engineer, Try this please:
<div>#Html.Label(DateTime.Now.ToString())</div>
Or like this:
<label for="">#DateTime.Now.ToString()</label>
DateTime dt = DateTime.Now;
String strDate="";
strDate = dt.ToString("MM/dd/yyyy hh:mm tt"); // 08/12/2016 02:22 PM
I am adding a custom header to a SharePoint master page and I would like to display the current time in four different time zones. However, I don't want to use the client's time as there is no way to know what time zone the client will be in, or if they have the correct time on their computer.
Ideally, the time should be displayed as follows:
Dallas: (UTC-6 w/ DST support) Zulu: (UTC) Iraq: (UTC+3) Afghanistan: (UTC+4.5)
My problem is that I really don't know anything about ASP.NET, as I'm a PHP guy myself. So I need a way to pass the serverTime as a variable that JavaScript can use to perform calculations on to display the correct time zone.
UPDATE:
I need the clock to update as each second changes. So it is a live time instead of a static time.
UPDATE 2:
This is the code I'm using, any suggestions?
<script runat="server">
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
End Sub
Public Function dtBase() As Double
Dim d1 As Date = New Date(1970, 1, 1)
Dim d2 As Date = Date.UtcNow
Dim ts As TimeSpan = d2 - d1
Return ts.TotalMilliseconds
End Function
</script>
<html>
<head>
<script type="text/javascript">
var serverTime=<%=dtBase%>
var clientTime = new Date().getTime();
var milliDiff = serverTime - clientTime;
function tO(){ return new Date(); }
function tN(){ x=new Date(tO().getUTCFullYear(),tO().getUTCMonth(),tO().getUTCDate(),tO().getUTCHours(),tO().getUTCMinutes(),tO().getUTCSeconds()); x.setTime(x.getTime()+milliDiff); return x; }
function lZ(x){ return (x>9)?x:'0'+x; }
// CST time (subtract 5 hours from UTC time)
// function dS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()-(5*3600000)); return x; }
// CST time (subtract 6 hours from UTC time)
function dS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()-(6*3600000)); return x; }
function dallasT(){ document.getElementById('DALLAS').innerHTML=eval(dT); setTimeout('dallasT()',1000); }
var dT="lZ(dS().getHours())+':'+lZ(dS().getMinutes())+':'+lZ(dS().getSeconds())";
// ZULU time (UTC time)
function zS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()); return x; }
function zuluT(){ document.getElementById('ZULU').innerHTML=eval(zT); setTimeout('zuluT()',1000); }
var zT="lZ(zS().getHours())+':'+lZ(zS().getMinutes())+':'+lZ(zS().getSeconds())";
// IRAQ time (add 3 hours to UTC time)
function iS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+(3*3600000)); return x; }
function iraqT(){ document.getElementById('IRAQ').innerHTML=eval(iT); setTimeout('iraqT()',1000); }
var iT="lZ(iS().getHours())+':'+lZ(iS().getMinutes())+':'+lZ(iS().getSeconds())";
// AFGN time (add 4.5 hours to UTC time)
function aS(){ x=new Date(tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()); x.setTime(x.getTime()+(4.5*3600000)); return x; }
function afgnT(){ document.getElementById('AFGN').innerHTML=eval(aT); setTimeout('afgnT()',1000); }
var aT="lZ(aS().getHours())+':'+lZ(aS().getMinutes())+':'+lZ(aS().getSeconds())";
</script>
</head>
<body onload="zuluT();dallasT();iraqT();afgnT();">
<table>
<tr>
<td>
DALLAS: <span id="DALLAS"> </span>
ZULU: <span id="ZULU"> </span>
IRAQ: <span id="IRAQ"> </span>
AFGN: <span id="AFGN"> </span>
</td>
</tr>
</table>
UPDATE 3:
Still don't know if the code worked. My SharePoint server rejected the page for the code blocks. I have absolutely zero idea how to do code-behind. The JS works, but if the client's time is off, the site displays incorrect times. Really wish I could just code this in PHP. I'd be done a week ago. ;)
UPDATE 4:
This update is for anyone that stumbles across this in the future looking for the answer to the problem. The code above has been updated to work correctly. The only catch is that SharePoint disallows code by default, so to enable it, you have to modify the web.config file. The web.config file is usually in the root directory of the site. Inside that file (which is XML), you'll find a tag. Somehwere inside of that, you should find , and inside of that, you should find . Inside of that tag, you want to add this:
<PageParserPath VirtualPath="/relative/path/to/your/file/here.aspx" CompilationMode="Always" AllowServerSideScript="true" />
I hope this helps y'all.
The server time is simply...
Now()
You can set the value of the text property of a label control or the value property of a HiddenField control to Now() and then access it through Javascript in the OnLoad event. You can also make a WebService in .Net that returns the server's current time (in JSON or XML) and call that through Javascript.
It isn't clear why you want to do this in JavaScript. Or JScript. Please, whatever you do, don't use JScript. JScript has a lot of large corporations stuck in IE6 and therefore also Windows XP. (See the 4th comment here, among other sources.)
JavaScript runs on the client, so you are dealing with the time on the client's local machine. It is possible, but more difficult, to ascertain the client's time zone, and base your calculations on that.
However, if you you use ASP.Net server-side code written in C# or VB, you will automatically be using the server's local time.
Local time is UTC + the time zone offset for that location, + an offset (typically +1) for daylight saving time, if in effect.
This page explains how to get UTC (or Zulu) time in C# or VB. Basically, it is
DateTime.Now.ToUniversalTime();
To add hours to that:
DateTime.Now.AddHours(3);
You can put a negative number (-3) to subtract hours.
You can combine those to adjust UTC:
DateTime.Now.AddHours(3).ToUniversalTime();