{"id":23183,"date":"2008-03-07T10:00:00","date_gmt":"2008-03-07T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/03\/07\/why-cant-i-convert-a-time-zone-abbreviation-into-a-time-zone\/"},"modified":"2008-03-07T10:00:00","modified_gmt":"2008-03-07T10:00:00","slug":"why-cant-i-convert-a-time-zone-abbreviation-into-a-time-zone","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080307-00\/?p=23183","title":{"rendered":"Why can&#039;t I convert a time zone abbreviation into a time zone?"},"content":{"rendered":"<table ALIGN=\"right\" STYLE=\"width: 20pc\">\n<tr>\n<td BGCOLOR=\"#C0F7FE\">\n<b>Public Service Announcement<\/b><br \/>\nDaylight Savings Time begins this weekend in\nmost parts of the United States.\n<\/td>\n<\/tr>\n<\/table>\n<p>\nSuppose you have a string of the form\n<code>\"Thu Mar 27 03:46:20 CST 2003\"<\/code>.\nHow can you parse this into something your program can manipulate,\nlike say a <code>SYSTEMTIME<\/code> or a <code>FILETIME<\/code>?\n<\/p>\n<p>\nBasically, you can&#8217;t in the general case.\nThe time zone abbreviation CST is ambiguous.\nIt could mean\nU.S.\/Canada Central Standard Time,\nAustralian Central Standard Time,\nChina Standard Time, or\nCuba Summer Time.\nThere may be other possibilities as well.\nWithout any other context, the time zone abbreviation CST\ncould mean any of those time zones.\n(This doesn&#8217;t stop people from asking for the feature anyway.\nMaybe they want fuzzy logic or psychic powers.)\nNote also that\n<a HREF=\"http:\/\/www.w3.org\/TR\/NOTE-datetime.html\">\nthere is an international standard for representing\ndates and times in text form<\/a>,\nincluding the time zone.\n<\/p>\n<p>\nOkay, back to the original problem.\nIn order to get a definite answer, you will need to restrict your domain\nto resolve the ambiguity.\nYou might decide, for example, that you only care about the four continental\nUnited States time zones.\nBelieve it or not, this is what JScript does!\n<\/p>\n<pre>\nvar fso = new ActiveXObject(\"Scripting.FileSystemObject\");\nvar f = fso.GetFolder(\"C:\\\\\");\nvar fc = new Enumerator(f.files);\nfor (; !fc.atEnd(); fc.moveNext()) {\n  WScript.echo(\"File: \" + fc.item());\n  WScript.echo(\"Date: \" + fc.item().DateLastModified);\n}\n<\/pre>\n<p>\nWhen I run this program via\n<code>cscript testprogram.js<\/code>, I get the following:\n<\/p>\n<pre>\nFile: C:\\AUTOEXEC.BAT\nDate: Sun Jan 9 17:13:09 PST 2005\nFile: C:\\boot.ini\nDate: Tue Nov 22 11:53:48 PST 2005\nFile: C:\\CONFIG.SYS\nDate: Sun Jan 9 17:13:09 PST 2005\nFile: C:\\hiberfil.sys\nDate: Thu Dec 14 23:29:00 PST 2006\nFile: C:\\IO.SYS\nDate: Sun Jan 9 17:13:09 PST 2005\nFile: C:\\MSDOS.SYS\nDate: Sun Jan 9 17:13:09 PST 2005\nFile: C:\\NTDETECT.COM\nDate: Tue Aug 10 11:00:00 PDT 2004\nFile: C:\\ntldr\nDate: Tue Aug 10 11:00:00 PDT 2004\nFile: C:\\pagefile.sys\nDate: Thu Dec 14 23:28:59 PST 2006\n<\/pre>\n<p>\nHey, look, that time zone got inserted.\nBut if we make a tiny change to the way we print the date\n<\/p>\n<pre>\nvar fso = new ActiveXObject(\"Scripting.FileSystemObject\");\nvar f = fso.GetFolder(\"C:\\\\\");\nvar fc = new Enumerator(f.files);\nfor (; !fc.atEnd(); fc.moveNext()) {\n  WScript.echo(\"File: \" + fc.item());\n  WScript.echo(<font COLOR=\"blue\">\"Date:\", fc.item().DateLastModified<\/font>);\n}\n<\/pre>\n<p>\nthe results are quite different:\n<\/p>\n<pre>\nFile: C:\\AUTOEXEC.BAT\nDate: 1\/9\/2005 5:13:09 PM\nFile: C:\\boot.ini\nDate: 11\/22\/2005 11:53:48 AM\nFile: C:\\CONFIG.SYS\nDate: 1\/9\/2005 5:13:09 PM\nFile: C:\\hiberfil.sys\nDate: 12\/14\/2006 11:29:00 PM\nFile: C:\\IO.SYS\nDate: 1\/9\/2005 5:13:09 PM\nFile: C:\\MSDOS.SYS\nDate: 1\/9\/2005 5:13:09 PM\nFile: C:\\NTDETECT.COM\nDate: 8\/10\/2004 11:00:00 AM\nFile: C:\\ntldr\nDate: 8\/10\/2004 11:00:00 AM\nFile: C:\\pagefile.sys\nDate: 12\/14\/2006 11:28:59 PM\n<\/pre>\n<p>\nIn this modified version, we&#8217;re print the time and date directly\ninstead of using the JScript conversion.\nThis time, the hard-coded U.S. English days of the week, months,\nand time zones aren&#8217;t present.\n(I haven&#8217;t checked whether OLE Automation follows local settings.)\n<\/p>\n<p>\n(Reminder:\nWhether daylight saving time is a good idea has\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2007\/11\/02\/5823449.aspx#comments\">\nalready been discussed<\/a>,\nso please don&#8217;t waste everybody&#8217;s time by bringing it up again.\nThanks.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Public Service Announcement Daylight Savings Time begins this weekend in most parts of the United States. Suppose you have a string of the form &#8220;Thu Mar 27 03:46:20 CST 2003&#8221;. How can you parse this into something your program can manipulate, like say a SYSTEMTIME or a FILETIME? Basically, you can&#8217;t in the general case. [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2,108],"class_list":["post-23183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history","tag-time"],"acf":[],"blog_post_summary":"<p>Public Service Announcement Daylight Savings Time begins this weekend in most parts of the United States. Suppose you have a string of the form &#8220;Thu Mar 27 03:46:20 CST 2003&#8221;. How can you parse this into something your program can manipulate, like say a SYSTEMTIME or a FILETIME? Basically, you can&#8217;t in the general case. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=23183"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/23183\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=23183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=23183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=23183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}