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

  • SEARCH
  • Home
  • 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 8528187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:44:48+00:00 2026-06-11T08:44:48+00:00

strptime_l is always returning null. I’m doing this in Objective-C. #import <time.h> #import <xlocale.h>

  • 0

strptime_l is always returning null. I’m doing this in Objective-C.

#import <time.h>
#import <xlocale.h>

/* Later on... */      

    const char *str = [dateStr UTF8String];
    const char *fmt = [@"EE LLLL d HH:mm:ss Z yyyy" UTF8String];
    struct tm timeinfo;
    memset(&timeinfo, 0, sizeof(timeinfo));
    char *ret = strptime_l(str, fmt, &timeinfo, NULL);

    NSDate *date = nil;

    if (ret) {
        time_t time = mktime(&timeinfo);

        date = [NSDate dateWithTimeIntervalSince1970:time];
    }

ret is always null. An example of dateStr‘s value is: Sat Sep 15 05:52:10 +0000 2012 and is always in that format.

Any ideas?

  • 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-06-11T08:44:49+00:00Added an answer on June 11, 2026 at 8:44 am

    You seem to be using the NSDateFormatter format instead of the strptime one. Take a look here for more info its specific date and time format.

    The following code should work:

    NSString *dateStr = @"Sat Sep 15 05:52:10 +0000 2012";
    
    const char *str = [dateStr UTF8String];
    const char *fmt = [@"%a %b %d %H:%M:%S %z %Y" UTF8String];
    struct tm timeinfo;
    memset(&timeinfo, 0, sizeof(timeinfo));
    char *ret = strptime_l(str, fmt, &timeinfo, NULL);
    
    NSDate *date = nil;
    
    if (ret) {
        time_t time = mktime(&timeinfo);
    
        date = [NSDate dateWithTimeIntervalSince1970:time];
    }
    

    By the way you could have achieved the same by simply doing:

    NSString *dateStr = @"Sat Sep 15 05:52:10 +0000 2012";
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EE LLLL d HH:mm:ss Z yyyy"];
    NSDate *date = [dateFormat dateFromString:dateStr];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can output a locale sensitive time format using strftime('%X') , but this always
I'm using this to convert date time strings to a unix timestamp: str(int(time.mktime(time.strptime(date,%d %b
I have this variable: $timestamp = strftime(%Y-%m-%d %h:%M:%S %a, time ()); I simply want
I also have a week number, extracted from another time object like this other_time.strftime('%W').to_i
I received the following script from a fellow programmer: from time import * start
When I write this strftime(%b %d, %Y %l:%I %p ,strtotime($runrows['date'])); it always displays incorrectly
I have this code : >>> import datetime >>> l = '2011-12-02' >>> t
I am able to parse strings containing date/time with time.strptime >>> import time >>>
My rails logger configuration currently logs the current time and UUID, like this: config.logger
I am parsing a file this way : for d in csvReader: print datetime.datetime.strptime(d[Date]+-+d[Time],

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.