c# - DST in JavaScript -


how can check in js file whether current date in dst or not?

in c# there below code available check this. can suggest similar code in js?

var timezone = timezone.currenttimezone var tzbyid = timezoneinfo.findsystemtimezonebyid(timezone.standardname); var localdate = timezoneinfo.converttimefromutc(datetime.utcnow, tzbyid); 

let's start c# code provided. have bug. findsystemtimezonebyid expects value id property of timezoneinfo object. looking standardname of timezone object, might work, time zones, , on english language systems. id not localized, names are. really, should never use timezone. use timezoneinfo. if want local timezoneinfo, use timezoneinfo.local.

but really, have written elaborate version of datetime.now. code doesn't other that. equivalent javascript new date().

so, asked how determine if current date in daylight saving time or not. assume meant local time zone. in c# datetime.now.isdaylightsavingtime. in javascript, bit trickier.

there few different ways, 1 pretty easy. see this site detailed explanation.

date.prototype.stdtimezoneoffset = function() { var jan = new date(this.getfullyear(), 0, 1); var jul = new date(this.getfullyear(), 6, 1); return math.max(jan.gettimezoneoffset(), jul.gettimezoneoffset()); }  date.prototype.dst = function() { return this.gettimezoneoffset() < this.stdtimezoneoffset(); } 

now can check new date().dst , simple true/false result.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -