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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:46:58+00:00 2026-06-13T20:46:58+00:00

Has anyone managed to use locale on OS X to derive a default local

  • 0

Has anyone managed to use locale on OS X to derive a default local date and time format ? (I need to parse simple dates and times in a variety of locales).

For the moment, I am resorting to osascript …

from subprocess import Popen, PIPE

cmd = "osascript -e " + """'
    tell (current date)
        set {its year, its month, its day} to {2001, 2, 3}
        set {its hours, its minutes, its seconds} to {4, 5, 6}
        return its short date string & tab & its time string
    end tell'"""

str_date, err_num = Popen(cmd, shell=True, \
    stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate()

str_date, _, str_time = str_date.rpartition('   ')
str_date_pattern = str_date.replace('2001', '%Y').replace('02', '%m').replace('03','%d')
str_time_pattern = str_time.replace('04', '%H').replace('05', '%M').replace('06', '%S').rstrip()

which returns something like:

'%d/%m/%Y', '%H:%M:%S'
  • 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-13T20:46:59+00:00Added an answer on June 13, 2026 at 8:46 pm

    Why not use the python-dateutil package instead?

    It’s parse function can handle most formats without having to configure the format:

    >>> from dateutil.parser import parse
    >>> parse('03/02/2001 04:05:06')
    datetime.datetime(2001, 3, 2, 4, 5, 6)
    

    Alternatively, you could try and translate the ICU format strings available via the defaults read command:

    $ defaults read .GlobalPreferences AppleICUDateFormatStrings
    {
        1 = "yyyy/M/d";
    }
    $ defaults read .GlobalPreferences AppleICUTimeFormatStrings
    {
        1 = "kk:mm ";
        2 = "kk:mm:ss ";
        3 = "kk:mm:ss  z";
        4 = "kk:mm:ss  v";
    }
    

    These are the locale settings configured via the Language & Text configuration panel.

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

Sidebar

Related Questions

Has anyone managed to use core-plot from wax? I have been trying recently, but
Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it
Has anyone managed to use the Concurrent Mark Sweep garbage collector (UseConcMarkSweepGC) in Hotspot
Has anyone managed to use the replicate method in Lotus Notes? I am trying
Has anyone managed to use Postgresql as a datasource for SSAS? The Postgresql .NET
Has anyone managed to get administration rights through the UAC without restarting the application
Has anyone successfully tried minifying AND concatenating all the jqGrid locale files so that
Has anyone succeeded in configuring ADFS2 to use Live Id (or Google, Yahoo etc)
I'm wondering if anyone has managed to integrate SASS into their RubyMine environment, and
Has anyone ported IJG JPEG code to C#? Are there any purely-managed JPEG libraries

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.