|
Aah, one of our customers had exactly this problem on their Windows 2012 servers - some were showing "GMT Daylight" Time, others "GMT Summer Time", even though they had all been built "exactly the same" (by a third party). It's a region/locale difference, one is English (US), the other is English (United Kingdom). I think it comes from the tzres.dll.
|
|
|
|
|
DerekTP123 wrote: ddd MMM dd yyyy hh:MM:ss GMT+nnnn (xxxxxxx)
I'm sure you can strip the unnecessary stuff off using a regex, easily.
|
|
|
|
|
Typescript to the rescue, format your date on the client side!!
interface Date {
format(pattern: string, utc?: boolean): string;
}
Date.prototype.format = function (pattern: string, utc?: boolean) {
var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
function ii(i: number, len?: number) {
var s = i + "";
len = len || 2;
while (s.length < len) s = "0" + s;
return s;
}
var y = utc ? this.getUTCFullYear() : this.getFullYear();
pattern = pattern.replace(/(^|[^\\])yyyy+/g, "$1" + y);
pattern = pattern.replace(/(^|[^\\])yy/g, "$1" + y.toString().substr(2, 2));
pattern = pattern.replace(/(^|[^\\])y/g, "$1" + y);
var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
pattern = pattern.replace(/(^|[^\\])MMMM+/g, "$1" + MMMM[0]);
pattern = pattern.replace(/(^|[^\\])MMM/g, "$1" + MMM[0]);
pattern = pattern.replace(/(^|[^\\])MM/g, "$1" + ii(M));
pattern = pattern.replace(/(^|[^\\])M/g, "$1" + M);
var d = utc ? this.getUTCDate() : this.getDate();
pattern = pattern.replace(/(^|[^\\])dddd+/g, "$1" + dddd[0]);
pattern = pattern.replace(/(^|[^\\])ddd/g, "$1" + ddd[0]);
pattern = pattern.replace(/(^|[^\\])dd/g, "$1" + ii(d));
pattern = pattern.replace(/(^|[^\\])d/g, "$1" + d);
var H = utc ? this.getUTCHours() : this.getHours();
pattern = pattern.replace(/(^|[^\\])HH+/g, "$1" + ii(H));
pattern = pattern.replace(/(^|[^\\])H/g, "$1" + H);
var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
pattern = pattern.replace(/(^|[^\\])hh+/g, "$1" + ii(h));
pattern = pattern.replace(/(^|[^\\])h/g, "$1" + h);
var m = utc ? this.getUTCMinutes() : this.getMinutes();
pattern = pattern.replace(/(^|[^\\])mm+/g, "$1" + ii(m));
pattern = pattern.replace(/(^|[^\\])m/g, "$1" + m);
var s = utc ? this.getUTCSeconds() : this.getSeconds();
pattern = pattern.replace(/(^|[^\\])ss+/g, "$1" + ii(s));
pattern = pattern.replace(/(^|[^\\])s/g, "$1" + s);
var f = utc ? this.getUTCMilliseconds() : this.getMilliseconds();
pattern = pattern.replace(/(^|[^\\])fff+/g, "$1" + ii(f, 3));
f = Math.round(f / 10);
pattern = pattern.replace(/(^|[^\\])ff/g, "$1" + ii(f));
f = Math.round(f / 10);
pattern = pattern.replace(/(^|[^\\])f/g, "$1" + f);
var T = H < 12 ? "AM" : "PM";
pattern = pattern.replace(/(^|[^\\])TT+/g, "$1" + T);
pattern = pattern.replace(/(^|[^\\])T/g, "$1" + T.charAt(0));
var t = T.toLowerCase();
pattern = pattern.replace(/(^|[^\\])tt+/g, "$1" + t);
pattern = pattern.replace(/(^|[^\\])t/g, "$1" + t.charAt(0));
var tz = -this.getTimezoneOffset();
var K = utc || !tz ? "Z" : tz > 0 ? "+" : "-";
if (!utc) {
tz = Math.abs(tz);
var tzHrs = Math.floor(tz / 60);
var tzMin = tz % 60;
K += ii(tzHrs) + ":" + ii(tzMin);
}
pattern = pattern.replace(/(^|[^\\])K/g, "$1" + K);
var day = (utc ? this.getUTCDay() : this.getDay()) + 1;
pattern = pattern.replace(new RegExp(dddd[0], "g"), dddd[day]);
pattern = pattern.replace(new RegExp(ddd[0], "g"), ddd[day]);
pattern = pattern.replace(new RegExp(MMMM[0], "g"), MMMM[M]);
pattern = pattern.replace(new RegExp(MMM[0], "g"), MMM[M]);
pattern = pattern.replace(/\\(.)/g, "$1");
return pattern;
};
|
|
|
|
|
HOLY GEEZUS! I like TypeScript and all but what What WHAT?!
Shouldn't This Be Easier(TM)
|
|
|
|
|
holymolly.. only 3 top line are typescript specific.. the rest is plain old javascript format function!
|
|
|
|
|
Don't worry, I made a javascript only version for ya! Much simplerer!
Date.prototype.format = function (pattern, utc) {
var MMMM = ["\x00", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var MMM = ["\x01", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dddd = ["\x02", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var ddd = ["\x03", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
function ii(i, len) {
var s = i + "";
len = len || 2;
while (s.length < len) s = "0" + s;
return s;
}
var y = utc ? this.getUTCFullYear() : this.getFullYear();
pattern = pattern.replace(/(^|[^\\])yyyy+/g, "$1" + y);
pattern = pattern.replace(/(^|[^\\])yy/g, "$1" + y.toString().substr(2, 2));
pattern = pattern.replace(/(^|[^\\])y/g, "$1" + y);
var M = (utc ? this.getUTCMonth() : this.getMonth()) + 1;
pattern = pattern.replace(/(^|[^\\])MMMM+/g, "$1" + MMMM[0]);
pattern = pattern.replace(/(^|[^\\])MMM/g, "$1" + MMM[0]);
pattern = pattern.replace(/(^|[^\\])MM/g, "$1" + ii(M));
pattern = pattern.replace(/(^|[^\\])M/g, "$1" + M);
var d = utc ? this.getUTCDate() : this.getDate();
pattern = pattern.replace(/(^|[^\\])dddd+/g, "$1" + dddd[0]);
pattern = pattern.replace(/(^|[^\\])ddd/g, "$1" + ddd[0]);
pattern = pattern.replace(/(^|[^\\])dd/g, "$1" + ii(d));
pattern = pattern.replace(/(^|[^\\])d/g, "$1" + d);
var H = utc ? this.getUTCHours() : this.getHours();
pattern = pattern.replace(/(^|[^\\])HH+/g, "$1" + ii(H));
pattern = pattern.replace(/(^|[^\\])H/g, "$1" + H);
var h = H > 12 ? H - 12 : H == 0 ? 12 : H;
pattern = pattern.replace(/(^|[^\\])hh+/g, "$1" + ii(h));
pattern = pattern.replace(/(^|[^\\])h/g, "$1" + h);
var m = utc ? this.getUTCMinutes() : this.getMinutes();
pattern = pattern.replace(/(^|[^\\])mm+/g, "$1" + ii(m));
pattern = pattern.replace(/(^|[^\\])m/g, "$1" + m);
var s = utc ? this.getUTCSeconds() : this.getSeconds();
pattern = pattern.replace(/(^|[^\\])ss+/g, "$1" + ii(s));
pattern = pattern.replace(/(^|[^\\])s/g, "$1" + s);
var f = utc ? this.getUTCMilliseconds() : this.getMilliseconds();
pattern = pattern.replace(/(^|[^\\])fff+/g, "$1" + ii(f, 3));
f = Math.round(f / 10);
pattern = pattern.replace(/(^|[^\\])ff/g, "$1" + ii(f));
f = Math.round(f / 10);
pattern = pattern.replace(/(^|[^\\])f/g, "$1" + f);
var T = H < 12 ? "AM" : "PM";
pattern = pattern.replace(/(^|[^\\])TT+/g, "$1" + T);
pattern = pattern.replace(/(^|[^\\])T/g, "$1" + T.charAt(0));
var t = T.toLowerCase();
pattern = pattern.replace(/(^|[^\\])tt+/g, "$1" + t);
pattern = pattern.replace(/(^|[^\\])t/g, "$1" + t.charAt(0));
var tz = -this.getTimezoneOffset();
var K = utc || !tz ? "Z" : tz > 0 ? "+" : "-";
if (!utc) {
tz = Math.abs(tz);
var tzHrs = Math.floor(tz / 60);
var tzMin = tz % 60;
K += ii(tzHrs) + ":" + ii(tzMin);
}
pattern = pattern.replace(/(^|[^\\])K/g, "$1" + K);
var day = (utc ? this.getUTCDay() : this.getDay()) + 1;
pattern = pattern.replace(new RegExp(dddd[0], "g"), dddd[day]);
pattern = pattern.replace(new RegExp(ddd[0], "g"), ddd[day]);
pattern = pattern.replace(new RegExp(MMMM[0], "g"), MMMM[M]);
pattern = pattern.replace(new RegExp(MMM[0], "g"), MMM[M]);
pattern = pattern.replace(/\\(.)/g, "$1");
return pattern;
};
modified 31-Mar-17 16:11pm.
|
|
|
|
|
SyntaxError: missing ) after formal parameters
You've left the TypeScript parameter types in there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Quote:
function ii(i: number, len?: number) {
You've corrected the outer function, but not the inner one.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
damn you man, this is way too much attention to detail!
I am having a sleepless night watching movie now!
|
|
|
|
|
Congratulations, your date is now "implementation-dependent" due to toString .
ECMA-262 wrote: 20.3.4.41.1 Runtime Semantics: ToDateString(tv)
The following steps are performed:
1. Assert: Type(tv) is Number.
2. If tv is NaN, return "Invalid Date".
3. Return an implementation-dependent String value that represents tv as a date and time in the current time
zone using a convenient, human-readable form.
Luckily there is a method toUTCString or a library "moment" to allow to explicitly say the format, since ECMA are more concerned by invariants (that almost no good javascript programmer have problem with) than dates (that almost everyone works with).
|
|
|
|
|
There are two basic rules for passing datetime between systems:
- Use UTC.
- When passing as string use a fixed format and not one that depends on local system settings.
The recommended string format is according to ISO 8601 - Wikipedia[^].
|
|
|
|
|
I completely agree with using ISO 8601!
(but I kindly refer to a Stackoverflow answer that fixes the (in my opinion, wrong) JSON behaviour of serializing a js Date to a UTC string and losing all timezone information).
|
|
|
|
|
It all depends on the requirements.
If you need time zone information, you must pass it too of course. If you don't need the TZ name, using the offset is fine because that can be simply parsed. If you need the name do not use the full name but the abbreviation (see List of time zone abbreviations - Wikipedia[^]).
Handling local times is always a nightmare. For this reason there is the general rule to always use UTC. Only when dates should be displayed they might be converted to local time.
When having tabular data containing multiple records, use UTC for the records and store the time zone information in a single record (e.g. within the user record). This applies especially when the timestamps has to be stored in binary format (like with databases).
|
|
|
|
|
|
You should also be very much aware to never trust JavaScript mixed type string concatenation.
Immanentize the Eschaton!
|
|
|
|
|
So, you GENERATED the URL.
You used the complicated format of the date/time string given to you by default, and hard to test manually.
As opposed to formatting the date in Javascript to be: YYYYMMDD_HHNNSS and simply parsing that on the other end?
Try to make your code immutable to the version of windows, etc.
|
|
|
|
|
Yes, I said I was being lazy. Yes, I know I did it a foolish way. The ONLY point of my post in Weird and Wonderful was to highlight a weird and wonderful (and undocumented, it would seem) change in the Time Zone description by Microsoft from "Daylight Time" to "Summer Time" with Win8 (and, it would seem, back to "Daylight Time" in Win10).
"This forum is purely for amusement"
|
|
|
|
|
I get the point of the post. But I want to make sure YOU and even OTHERS realize that the solution is to really work to insulate yourself from these things from the jump.
In fact, I just "auto saved" a file in my program, and I forced the YYYYMMDD_HHNNSS format to the prefix, so it is sortable, and gives a clue as to when it was made, how old, etc.
|
|
|
|
|
Why are you screwing around with strings?
In Javascript "Date.now()" returns the number of milliseconds since 1/1/1970 (GMT). Pass that number in the URL.
On the server-side:
new DateTime(1970,1,1) + new TimeSpan(now * 1000)
Give you the date/time.
Truth,
James
|
|
|
|
|
Ah! Many happy memories of hair tearing and cat kicking. So many variables and none of them nice.
My best suggestion is to convert all dates into standard strings using the inbuilt date formatting functions. Whatever you do, don't pass dates as date objects. You will regret it...
We're philosophical about power outages here. A.C. come, A.C. go.
|
|
|
|
|
Quote: I have some Javascript code
That's where I stopped, already more horror than I can take, can't risk reading the continuation.
Be strong.
|
|
|
|
|
Ha ha! The issue was nothing to do with Javascript, rather Microsoft's random renaming of time zones.
|
|
|
|
|
There is a standard date/time format when interchanging information between different applications:
ISO 8601
string data = "2017-04-14T01:27:00+02";
DateTime dt = DateTime.Parse(data);
|
|
|
|
|
|