Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:02:38+00:00 2026-05-31T00:02:38+00:00

EDIT: Basically, I’m looking to do this, in UTC-time, ideally via ISO-8601: Python: datetime.datetime

  • 0

EDIT: Basically, I’m looking to do this, in UTC-time, ideally via ISO-8601:

  1. Python: datetime.datetime —> ISO-8601 string
  2. Python: ISO-8601 string —> datetime.datetime
  3. Obj-C: NSDate —> ISO-8601 NSString
  4. Obj-C: ISO-8601 NSString —> NSDate

This seems like it should be really simple, but I can’t seem to figure it out.

Python code, converting to a string:

>>> import datetime
>>> datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S %z")
'2012-03-08 00:07:31 '

Note that the time-zone info %z is printed as an empty string, since utcnow() returns a naive datetime object. How do I turn it into an aware one and get it to print like the following?

'2012-03-08 00:07:31 +0000'

On the Obj-C side of things:

// This fails and prints (null) since the timezone is missing.
NSString *pythonDate1 = @"2012-03-07 23:51:58 ";
NSDate   *objCDate1   = [NSDate dateWithString:pythonDate1];
NSLog(@"%@", objCDate1);

// This works, manually adding in the "+0000".
NSString *pythonDate2 = @"2012-03-07 23:51:58 +0000";
NSDate   *objCDate2   = [NSDate dateWithString:pythonDate2];
NSLog(@"%@", objCDate2);

Printout:

2012-03-07 19:14:47.848 Untitled 3[3912:707] (null)
2012-03-07 19:14:47.849 Untitled 3[3912:707] 2012-03-07 23:51:58 +0000

I’m not quite sure how to go back from an NSDate to a datetime.datetime object either. Any help is greatly appreciated! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:02:39+00:00Added an answer on May 31, 2026 at 12:02 am

    if you don’t want to deal with timezone objects, and your time is in UTC, why not just append the “Z” defining Zulu/Zero to the end as defined in ISO-8601

    >>> datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
    '2012-03-08T00:07:31Z'
    

    Unless of course Obj-C doesn’t support ISO-8601 formatting…

    Or, if your still only going to use utcnow(), you can cheat and just add +00:00:

    >>> datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S +00:00")
    '2012-03-08 00:07:31 +00:00'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I am basically running into the following documented issue . I am using
I'm trying to load a page that is basically an edit form inside a
I have a relatively big SSIS package which I'm trying to edit. I basically
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
I have a ISO 8601 date, lets say: 2012-01-19T19:00-05:00 My machine timezone is GMT+1
How can I change the Amazon S3 url from http://bucket.amazons3.com/imagepath.jpg to http://image.mydomain.com/imagepath.jpg EDIT: Basically
So I have some data that looks like this: stringToSearch = 'this string needs
Basically this is what I am trying to achieve. classname@address(?)[original toString() ], object's name,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.