It is a pretty simple problem but looking through most of the answers and MS documentation, I could not find a simple way to use the abbreviated timezone information from Unix system in ParseExact function of DateTime in Powershell v4.   The date value that I receive is like December 29, 2016 2:04:26 PM EST  All of the elements in above date time are easily mapped except the "EST". This can of course be EST, EDT, PST, PDT or any other timezone.   MS timezone seems to require the full time zone name or id. How do we lookup EST in MS timezone in powershell?  Update* We essentially decided to ignore the timezone since we are interested in the day not the specific time of the day. There does not seem to be a simple answer except adding a case or lookup type statement and then converting it to PS style timezone (-5:00) etc.  The question that was cited as duplicate was answered 9 years ago. PS has gone through many iterations in this period so it should be reasonable to ask this question for a simpler resolution.
32919
I'm trying to parse an international datetime string similar to:  24-okt-08 21:09:06 CEST   So far I've got something like:  CultureInfo culture = CultureInfo.CreateSpecificCulture("nl-BE"); DateTime dt = DateTime.ParseExact("24-okt-08 21:09:06 CEST",     "dd-MMM-yy HH:mm:ss ...", culture);   The problem is what should I use for the '...' in the format string? Looking at the  MSDN page doesn't seem to list a format string for parsing timezones in PST/CEST/GMT/UTC form.
67823
I have created a field_time_zone field for the Article content type. I want to set the allowed values for that field to the values returned from system_time_zones(). For this, I implemented hook_form_alter() using the following code. $zones = system_time_zones(); $entityManager = \Drupal::service('entity_field.manager'); $fields = $entityManager-&gt;getFieldStorageDefinitions('node', 'local_market'); $options = options_allowed_values($fields['field_time_zone']);  if(empty($options)) { $options =  $zones; $form['field_time_zone']['widget']['#options'] = $options; }  The code adds the desired values, but the node cannot be saved, as it throws the following error.  The value you selected is not a valid choice.  How can I set the allowed values for a text (list) field?
52755
I need to get the current time but to be in type DateTime. I use:  DateTime now = System.now();   but it returns wrong time. I execute the code in 2017-08-04 00:38:46 AM but it returns     00:38:46:023 USER_DEBUG [138]|DEBUG|now 2017-08-03 21:38:46   How can I get my correct current local time 2017-08-04 00:38:46?  I had even tried with:  DateTime now = DateTime.parse(System.Now().format());   but I still get wrong time.     01:10:09:021 USER_DEBUG [139]|DEBUG|now 2017-08-03 22:10:00   How can I get the correct current local time?
33000
Does the .Net DateTime contain information about time zone where it was created?   I have a library parsing DateTime from a format that has "+zz" at the end, and while it parses correctly and adjusts a local time, I need to get what the specific time zone was from the DateTime object.   Is this possible at all? All I can see is DateTime.Kind, which specifies if time is local or UTC.
101677
I'd really like a user option to show all dates as yyyy-mm-dd HH:mm after the 2 day mark. I find the existing non-standard semi-verbose American Mon DD 'YY style date to be ugly and difficult to parse.  I am not asking for anything complicated here, just a simple user option to show the date and time in the international ISO 8601 format across the board. Since it's already in the tooltip everywhere, it should be a simple change to optionally show it in the page body for those users who want it.  Secondarily, if it's not too difficult, I'd very preferably like to see date &amp; times in my local time, rather than the UTC time as is currently shown used. It seems to make much more sense to me for see a question "asked 2014-02-04 10:19" as being my local time - I don't know what UTC is without using a converter (in this the before-2-days "asked 6 hours ago" is quite good).  (Re-raising this feature-request at the explicit behest of moderator Anna Lear; please don't close as a duplicate).
102384
I am still not able to get the correct difference, really struggling to make it working. The business hour set from 10 AM to 7 PM  BusinessHours bh = [SELECT FridayEndTime,FridayStartTime,Id,MondayEndTime,MondayStartTime,                     FROM BusinessHours where Name='Test Business Hour'                     LIMIT 1]; Time startTime = bh.MondayStartTime;        Time endTime = bh.MondayEndTime;  Date d = Date.today(); Datetime monTodaystart = Datetime.newInstance(d.year(),d.month(),d.day(),startTime.hour(), startTime.minute(),startTime.second()); Datetime monTodayend = Datetime.newInstance(d.year(),d.month(),d.day(),endTime.hour(), endTime.minute(),endTime.second()); System.debug('monTodaystart :: '+monTodaystart);     System.debug('monTodayend :: '+monTodayend);   Long diff = BusinessHours.diff(bh.Id, monTodaystart, monTodayend); System.debug('diff  :: '+diff);   I tried this simple example, but still its not working why ? How we can manipulate it ?  Datetime monTodaystart = Datetime.newInstance(2017,8,20,10,0,0); Datetime monTodayEnd = Datetime.newInstance(2017,8,20,17,0,0); System.debug('ID : '+bh.Id);  Long diff = BusinessHours.diff(bh.Id, monTodaystart,monTodayEnd); System.debug('diff  :: '+diff);   I dont think I should used the API here, instead I should use my custom logic, looks like some bug in the API still exists.
179
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really compelling backwards-compatible reason for it, particularly because of the regional settings issue with using date. See @npocmaka's     What's a Windows command line statement(s) I can use to get the current datetime in a format that I can put into a filename?  I want to have a .bat file that zips up a directory into an archive with the current date and time as part of the name, for example, Code_2008-10-14_2257.zip. Is there any easy way I can do this, independent of the regional settings of the machine?  I don't really mind about the date format, ideally it'd be yyyy-mm-dd, but anything simple is fine.  So far I've got this, which on my machine gives me Tue_10_14_2008_230050_91:  rem Get the datetime in a format that can go in a filename. set _my_datetime=%date%_%time% set _my_datetime=%_my_datetime: =_% set _my_datetime=%_my_datetime::=% set _my_datetime=%_my_datetime:/=_% set _my_datetime=%_my_datetime:.=_%  rem Now use the timestamp by in a new ZIP file name. "d:\Program Files\7-Zip\7z.exe" a -r Code_%_my_datetime%.zip Code   I can live with this, but it seems a bit clunky. Ideally it'd be briefer and have the format mentioned earlier.  I'm using Windows Server 2003 and Windows&nbsp;XP Professional. I don't want to install additional utilities to achieve this (although I realise there are some that will do nice date formatting).
117454
My understanding is that the system timezone is CST. Is this correct? When Day Light Saving time occurs does this change to CDT?
81739
If I have a Linq to SQL expression like this:    from subscription in dbContext.Subscriptions  where subscription.Expires &gt; DateTime.Now select subscription   I want this to to use the SQL Servers GETDATE() function instead of the time of the machine running the C# program.  The next question would be how to translate this:  DateTime.Now.AddDays(2)   to this:  DATEADD(dd, 2, GETDATE())
77368
Some issues with timezones in PHP have been in the back of my mind for a while now, and I was wondering if there are better ways to handle it than what I'm currently doing.  All of the issues revolve around reformating database stored dates:  When dealing with a site that has to support multiple timezones (for users), to normalize the timezone offest of stored timestamps I always store it with the server timezone using the CURRENT_TIMESTAMP attribute or the NOW() function.   This way I don't have to consider what timezone was set for PHP when the timestamp was entered (since PHP time functions are timezone aware). For each user, according to his preference I set the timezone somewhere in my bootstrap file using:  date_default_timezone_set($timezone);   When I'm looking to format dates with the php date() function, some form of conversion has to take place since MySQL currently stores timestamp in the format Y-m-d H:i:s. With no regard to timezone, you could simply run:  $date = date($format,strtotime($dbTimestamp));   The problem with this is that date() and strtotime() are both timezone aware functions, meaning that if the PHP timezone is set differently from the server timezone, the timezone offset will apply twice (instead of once as we would like).  To deal with this, I usually retrieve MySQL timestamps using the UNIX_TIMESTAMP() function which is not timezone aware, allowing my to apply date() directly on it - thereby applying the timezone offset only once.  I don't really like this 'hack' as I can no longer retrieve those columns as I normally would, or use * to fetch all columns (sometimes it simplifies queries greatly). Also, sometimes it's simply not an option to use UNIX_TIMESTAMP() (especially when using with open-source packages without much abstraction for query composition).  Another issue is when storing the timestamp, when usage of CURRENT_TIMESTAMP or NOW() is not an option - storing a PHP generated timestamp will store it with the timezone offset which I would like to avoid.  I'm probably missing something really basic here, but so far I haven't been able to come up with a generic solution to handle those issues so I'm forced to treat them case-by-case. Your thoughts are very welcome
56103
I currently have the following function: public String formatForGermany(Datetime targetTime) {     return this.format(targetTime, 'Europe/Berlin'); }  private String format(Datetime targetTime, String zone) {     Integer offset = TimeZone.getTimeZone(zone)             .getOffset(targetTime);     return targetTime.addSeconds(offset / 1000)             .format('HH:mm'); }  This works fine the input value is GMT. However, it seems in some contexts (TBD), Salesforce seems to anticipate this transformation is wanted and does it for me, in which case the offset gets applied twice, with the result that I display (for example) 14:00 instead of 12:00. Is there some way I can check whether the time has already been offset and either not apply it or adjust the offset accordingly?
82168
I was answering this  question and found strange result:   select * from  pg_timezone_names where name = 'Europe/Berlin' ;      name      | abbrev | utc_offset | is_dst  ---------------+--------+------------+--------  Europe/Berlin | CET    | 01:00:00   | f   and next query  select id,    timestampwithtimezone,    timestampwithtimezone at time zone 'Europe/Berlin' as berlin,    timestampwithtimezone at time zone 'CET' as cet  from data ;  id  | timestampwithtimezone  |       berlin        |         cet           -----+------------------------+---------------------+---------------------  205 | 2012-10-28 01:30:00+02 | 2012-10-28 01:30:00 | 2012-10-28 00:30:00  204 | 2012-10-28 02:00:00+02 | 2012-10-28 02:00:00 | 2012-10-28 01:00:00  203 | 2012-10-28 02:30:00+02 | 2012-10-28 02:30:00 | 2012-10-28 01:30:00  202 | 2012-10-28 02:59:59+02 | 2012-10-28 02:59:59 | 2012-10-28 01:59:59  106 | 2012-10-28 02:00:00+01 | 2012-10-28 02:00:00 | 2012-10-28 02:00:00   I'm using PostgreSQL 9.1.2 and ubuntu 12.04. Just checked that on 8.2.11 result is the same.  According to  it doesn't matter if I use name or abbreviation.  Is this a bug? Am I doing something wrong? Can someone explain this result?    EDIT For the comment that CET is not Europe/Berlin.  I'm just selecting values from pg_timezone_names.  select * from  pg_timezone_names  where abbrev ='CEST';  name | abbrev | utc_offset | is_dst  ------+--------+------------+--------   and  select * from  pg_timezone_names  where abbrev ='CET';         name         | abbrev | utc_offset | is_dst  ---------------------+--------+------------+--------  Africa/Tunis        | CET    | 01:00:00   | f  Africa/Algiers      | CET    | 01:00:00   | f  Africa/Ceuta        | CET    | 01:00:00   | f  CET                 | CET    | 01:00:00   | f  Atlantic/Jan_Mayen  | CET    | 01:00:00   | f  Arctic/Longyearbyen | CET    | 01:00:00   | f  Poland              | CET    | 01:00:00   | f  .....   During winter Europe/Berlin is +01. During summer it is +02.  EDIT2 In 2012-10-28 timezone has change from summer time to winter time at 2:00. This two records have the same value in Europe/Berlin:  204 | 2012-10-28 02:00:00+02 | 2012-10-28 02:00:00 | 2012-10-28 01:00:00 106 | 2012-10-28 02:00:00+01 | 2012-10-28 02:00:00 | 2012-10-28 02:00:00   This suggest that if I use one of abbreviations (CET or CEST) for big data range (summer time and winter time) result will be wrong for some of records. Will be good if I use 'Europe/Berlin'.  I changed the system time to '2012-01-17' and pg_timezone_names has changed also.  select * from  pg_timezone_names  where name ='Europe/Berlin';      name      | abbrev | utc_offset | is_dst  ---------------+--------+------------+--------  Europe/Berlin | CEST   | 02:00:00   | t
120935
Context: MySQL version  On MySQL 5.7.17 (as shown by SHOW VARIABLES LIKE "%version%";)  Context: MySQL timezone settings  and with SELECT @@global.time_zone, @@session.time_zone; yielding  +--------------------+---------------------+ | @@global.time_zone | @@session.time_zone | +--------------------+---------------------+ | SYSTEM             | SYSTEM              | +--------------------+---------------------+   ...which means the server tracks the system timezone.  Context: System timezone  This being a Linux, we check the system timezone like this (output redacted):  $ timedatectl       Local time: Wed 2018-02-14 13:21:30 GMT   Universal time: Wed 2018-02-14 13:21:30 UTC         RTC time: Wed 2018-02-14 13:21:30        Time zone: Europe/London (GMT, +0000)   Context: What we know    (there is no clear description of this in , except "MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.)"; note that "converts TIMESTAMP values to UTC for storage" actually makes sense only as an implementor's note, it's not useful to the user - what is important is that TiMEZONE always returns the correct value in whatever timezone one is in, while DATETIME will always return the same value in whatever timezone one is in)   Context: Current time  It's now around :  $ date +"The current time is %s alias %c" The current time is 1518617572 alias Wed 14 Feb 2018 14:12:52 GMT   Problem  Let's run:  SELECT NOW(),FROM_UNIXTIME(0),UNIX_TIMESTAMP(),FROM_UNIXTIME(UNIX_TIMESTAMP());   The output (suitably pivoted by hand; there should be an option to do that):  NOW()                            2018-02-14 14:15:13  -- Display "now" in SYSTEM timetone: OK FROM_UNIXTIME(0)                 1970-01-01 01:00:00  -- Display 1970-01-01 00:00:00 in SYSTEM timetone: NOT OK UNIX_TIMESTAMP()                 1518617713           -- Correct unixtime FROM_UNIXTIME(UNIX_TIMESTAMP())  2018-02-14 14:15:13  -- Same as NOW(): OK   In the above everything is fine, except the FROM_UNIXTIME(0) giving 1970-01-01 01:00:00, which is one hour off. If Unix Time 0 were displayed in UTC, it would give 1970-01-01 00:00:00 (or would it?)  This happens if I connect locally or from a remote machine.  To make doubly sure, I checked by coercing to DATETIME. The same happens:  CREATE TEMPORARY TABLE test (N DATETIME, FUX DATETIME, UXT LONG, NN DATETIME); INSERT INTO test SELECT NOW(),FROM_UNIXTIME(0),UNIX_TIMESTAMP(),FROM_UNIXTIME(UNIX_TIMESTAMP()); SELECT * FROM test; +---------------------+---------------------+------------+---------------------+ | N                   | FUX                 | UXT        | NN                  | +---------------------+---------------------+------------+---------------------+ | 2018-02-14 14:19:51 | 1970-01-01 01:00:00 | 1518617991 | 2018-02-14 14:19:51 | +---------------------+---------------------+------------+---------------------+
55745
I want to enter time data into excel sheet in mm:ss format. The problem is - that although the cell format is mm:ss, if I enter the data like this:  12:33 the actual value stored is 12 hours and 33 min.  if I want 12 min and 33 sec, I need to enter 0:12:33  Is there a way to make the cell accept 12:33 as mm:ss ?
109802
I'm specifically looking to change the formatting in two places:  On the desktop, the date/time reads "Sat 21:05". I would like it to read "23-Jul-11 21:05" or "23 Jul 11 21:05". In other words, I want to change the display of the day of week to display the day, short month name, and short year.  On the login screen, the date/time reads "Sat 9:06 PM". I would like to change it to either the same as the desktop ("23-Jul-11 21:05" or "23 Jul 11 21:05") or the preferred display of the full date in the format ("Saturday, 23 July 2011 21:05") where the full day, date, full month, full year, and time (in 24-hour format) is displayed.  I don't see any options to adjust this. I would suspect it's possible, but I'm not sure what config file it would be in or what options I would adjust.
49687
This is primarily for Windows 7, but I work in multiple versions and would happy to be able to do it in as many of them as possible.  Currently, when I open Explorer and look at a list of files, the date modified column shows something like:  09/18/2013 10:03  I would like it to display:  09/18/2013 10:03:42  I've tried changing the region and language settings for the short time format from HH:mm to HH:mm:ss, but it says it ignores seconds for that.  Does that mean I'm just out of luck?  And again, I'd like to be able to do this in any other  previous versions of Windows too.  It's useful for me as a developer to be able to see the seconds in a lot of situations.  Minor clarification: I did find , which helped me to improve the file properties display, but I wanted to be able to view the full timestamp for all the files in a folder at once, instead of individually.
14455
I'm trying to create a unit test to test the case for when the timezone changes on a machine because it has been incorrectly set and then corrected.  In the test I need to be able to create DateTime objects in a none local time zone to ensure that people running the test can do so successfully irrespective of where they are located.  From what I can see from the DateTime constructor I can set the TimeZone to be either the local timezone, the UTC timezone or not specified.  How do I create a DateTime with a specific timezone like PST?