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 6850399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:07:11+00:00 2026-05-27T01:07:11+00:00

I have this problem with displaying a date for the user based on the

  • 0

I have this problem with displaying a date for the user based on the user’s locale. But I want the date to be composed of digits only. For example: 2011/12/04 19:20:11. The problem is that I’ve tried to use NSDateFormatter and depending on the locale it can display an only numerical date or one with words like this: Jan 1 2011, 19:20:11. I want the locale to only affect the order of the month, day and year. Can this be done?

  • 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-27T01:07:11+00:00Added an answer on May 27, 2026 at 1:07 am

    To be honest I thought this was a poor question until I read the last line. “I want the locale to only affect the order of the month, day and year. Can this be done?”

    A fixed date format such as [formatter setDateFormat:@"HH:mm"] will not be affected by locale changes. The best thing to do is to use a ‘NSDateFormatterStyle‘ to do the heavy lifting for you.

    Part of your problem was that you did not set the correct date formatter style. NSDateFormatterShortStyle already outputs the date format you want.

    As far as the time format goes, if the user has their system set to 24hour clock then NSTimeZoneNameStyleShortGeneric should work right out of the box. But if not that can be fixed. The beauty of it is you don’t have to check.

    // Example Date Now
    NSDate *now = [NSDate date];
    // Formatter set to proper locale by default
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    // Set formatter to short styles
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSTimeZoneNameStyleShortGeneric];
    

    At this point your formatter will have already setup it’s own format string “M/d/yy h:mm:ss a“, this would be for the US. So at this point all we have to do is change the format slightly.

    // Remove the AM/PM from the format string
    formatter.dateFormat = [formatter.dateFormat stringByReplacingOccurrencesOfString:@"a" withString:@""];
    // Change 12h clock to 24h clock
    formatter.dateFormat = [formatter.dateFormat stringByReplacingOccurrencesOfString:@"h" withString:@"H"];
    

    Now your date format should be “M/d/yy H:mm:ss“. Which is the version you would want for the US. You can confirm with a log statement.

    NSLog(@"%@",[formatter stringFromDate:now]);
    

    Note that when you change the ‘h‘ in the format to ‘H‘ you don’t care where it is. So if in some locale they were to have a reversed time format it would be changed, but left in it’s original position.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem displaying/editing a date in MVC 3. I have set
i have a problem here of displaying a date type from ms access db
I have this problem I'm hoping someone knows the answer to. I have an
I have this problem where I open Visual Studio and the internal windows are
i have this problem to find a particular xml node l have post this
I have this problem I've been trying to tackle for a while. I have
i have this problem: ms-access could not delete and i found a potential solution
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem that my sites uses alot of ajax and when a
I have this problem containing some inequations and requirement to minimize a value. After

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.