Title: Add One New DateTime Parsing Format · Issue #11719 · PowerShell/PowerShell · GitHub
Open Graph Title: Add One New DateTime Parsing Format · Issue #11719 · PowerShell/PowerShell
X Title: Add One New DateTime Parsing Format · Issue #11719 · PowerShell/PowerShell
Description: Yesterday I posted a suggestion that we have a new special format for Get-Date that creates the SecondsSinceEpoch (aka UnixTime) for users. Additionally I think we should have built into the language the ability to easily parse a UnixEpo...
Open Graph Description: Yesterday I posted a suggestion that we have a new special format for Get-Date that creates the SecondsSinceEpoch (aka UnixTime) for users. Additionally I think we should have built into the langua...
X Description: Yesterday I posted a suggestion that we have a new special format for Get-Date that creates the SecondsSinceEpoch (aka UnixTime) for users. Additionally I think we should have built into the langua...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/11719
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add One New DateTime Parsing Format","articleBody":"Yesterday I posted a suggestion that we have a new special format for Get-Date that creates the SecondsSinceEpoch (aka UnixTime) for users.\r\n\r\nAdditionally I think we should have built into the language the ability to easily parse a UnixEpoch timestamp back into a DateTime.\r\n\r\nVarious existing parsing that works today:\r\n```\r\n$aDate = [DateTime]\"2020-01-28T17:32:18.4986003-06:00\" # (conversion back from the format of Format \"o\")\r\n$bDate = [DateTime]\"2020-01-28T17:36:39\" # (conversion back from the format of Format \"s\")\r\n$cDate = [DateTime]\"Tue, 28 Jan 2020 17:37:43 GMT\" # (conversion back from the format of Format \"r\")\r\n$dDate = [DateTime]\"2020-01-28 17:38:24Z\" # (conversion back from the format of Format \"u\")\r\n$eDate = [DateTime]\"7/25/2013 6:37:31 PM\" \r\n$fDate = [DateTime]\"2013-07-25 14:26:00\" \r\n$gDate = [DateTime]\"7/25/2013 14:26:00\"\r\n$hDate = [DateTime]\"2013-07-25 6:37:31 PM\"\r\n```\r\nBut we can't currently put in $AUnixDate = [DateTime]\"1374755180\" and end up with a valid DateTime object (which would be of UTC kind)\r\n\r\nA discussion by Randy James at https://stackoverflow.com/questions/17859421/parse-datetime-in-multiple-formats suggests perhaps something along these lines for processing this in another language:\r\n```\r\npublic DateTime ParseRequestDate()\r\n{\r\n // https://stackoverflow.com/questions/2883576/how-do-you-convert-epoch-time-in-c\r\n\r\n CultureInfo enUS = new CultureInfo(\"en-US\");\r\n\r\n var dt = \"1374755180\";\r\n //var dt = \"7/25/2013 6:37:31 PM\";\r\n //var dt = \"2013-07-25 14:26:00\";\r\n\r\n DateTime dateValue;\r\n long dtLong;\r\n\r\n // Scenario #1\r\n if (long.TryParse(dt, out dtLong))\r\n return dtLong.FromUnixTime();\r\n\r\n // Scenario #2 & #3\r\n var formatStrings = new string[] { \"MM/dd/yyyy hh:mm:ss tt\", \"yyyy-MM-dd hh:mm:ss\" };\r\n if (DateTime.TryParseExact(dt, formatStrings, enUS, DateTimeStyles.None, out dateValue))\r\n return dateValue;\r\n\r\n throw new SomeException(\"Don't know how to parse...\");\r\n}\r\n\r\n```\r\n","author":{"url":"https://github.com/scotthardwick","@type":"Person","name":"scotthardwick"},"datePublished":"2020-01-29T15:07:01Z","url":"https://github.com/PowerShell/PowerShell/issues/11719"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9747f9b2-9182-8ce7-1c56-8b1c19023539 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C210:160FD0:2B2FBD7:3C3F889:6AFD5D22 |
| html-safe-nonce | f99b864d78a9cd89d8efab2343d29298488b8c03f54d7349a9c0656b3e80ce36 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjEwOjE2MEZEMDoyQjJGQkQ3OjNDM0Y4ODk6NkFGRDVEMjIiLCJ2aXNpdG9yX2lkIjoiODY3MDMxMDI0NjcwMDExMzE4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 169b3039318bf22ef8cd30e47ad59151cc954db9191cbc4168f91f392dc3d81b |
| hovercard-subject-tag | issue:556923177 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/11719/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f4e37f0097a40093db2bba35327246621777089ff9132ca8b507372df9c35094/PowerShell/PowerShell/issues/11719 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f4e37f0097a40093db2bba35327246621777089ff9132ca8b507372df9c35094/PowerShell/PowerShell/issues/11719 |
| og:image:alt | Yesterday I posted a suggestion that we have a new special format for Get-Date that creates the SecondsSinceEpoch (aka UnixTime) for users. Additionally I think we should have built into the langua... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scotthardwick |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width