> Le 1 sept. 2019 à 01:10, Carl Hoefs via Cocoa-dev <cocoa-dev@lists.apple.com> 
> a écrit :
> 
> 
>> On Aug 31, 2019, at 2:51 AM, Allan Odgaard via Cocoa-dev 
>> <cocoa-dev@lists.apple.com> wrote:
>> 
>> On 31 Aug 2019, at 2:49, Carl Hoefs via Cocoa-dev wrote:
>> 
>>> Same result if I run it as a system daemon. So as you suggest it seems 
>>> there could be some sort of environment sensitivity going on. If only I 
>>> knew what env var to set in the shell... UTC really isn't what I'm looking 
>>> for.
>> 
>> The issue appears to be that `NSLog` sends your format string and arguments 
>> to the unified logging system, this is what Xcode and Console displays, and 
>> here you get dates formatted using the local time zone.
>> 
>> But it *also* does a simple `stringWithFormat:` and sends the result to 
>> standard error, at least when running in a terminal. This is where you are 
>> seeing a more crude formatting of the date which is not adjusted to the 
>> local time zone.
>> 
>> Open a new tab in your terminal, in that tab run this command:
>> 
>>      log stream|grep 'Configured date'
>> 
>> Now run your executable, and in the tab where it is running, you should see 
>> the UTC date, but in the tab where you are watching the log stream, you get 
>> the local date.
>> _______________________________________________
>> 
> 
> Thanks for the input! 
> 
> I realized this is occurring because I'm allowing macOS to generate the date 
> string according to its whims. If I do the string generation, then I can get 
> consistent results. So I added the following line to my code:
> 
>    NSString *dateString = [NSDateFormatter 
> localizedStringFromDate:configuredDate dateStyle:NSDateFormatterFullStyle 
> timeStyle:NSDateFormatterLongStyle];
> 
> and now I get a standardized string I can at least can live with, valid for 
> all situations:
> 
> Configured date: Saturday, August 31, 2019 at 3:55:02 PM PDT
> 

Note that your output is still Local dependent and can change from on system to 
an other.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to