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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:57:11+00:00 2026-05-19T11:57:11+00:00

import time print time.strftime(%a, %d %b %Y %I:%M %p %Z, time.gmtime()) I live in

  • 0
import time
print time.strftime("%a, %d %b %Y %I:%M %p %Z", time.gmtime())

I live in California. For some reason, this code is reporting the time in GMT, instead of respecting the system time zone. I know that strftime knows I’m in pacific, because it still prints ‘PST’ at the end, but it’s still 8 hours ahead. Is anyone else noticing this? Anyone know what’s either wrong with my system or my code?

EDIT:
running date at the command line gives me the correct date. Additionally, I’ve run this on two different computers (mac and linux) and they both report 8 hours ahead. Are you expected to correct for timezone before using strftime?

  • 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-19T11:57:12+00:00Added an answer on May 19, 2026 at 11:57 am

    time.gmtime() returns the time in UTC. What you need is time.localtime(), which is timezone-aware. This behaviour is well-documented in the time module documentation.

    EDIT:

    To convert any time.time() style timestamp to a struct_time, you can supply an argument to
    time.localtime():

    >>> print time.strftime("%a, %d %b %Y %I:%M:%S %p %Z", time.localtime(10.5))
    Thu, 01 Jan 1970 02:00:10 AM EET
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code I'm using is: import time print(time.strftime(%H:%M:%S)) In the dynamic shell, this (as
I have a date output like >>> import time >>> print time.strftime(%d %B) 19
The Problem This code #!/usr/bin/env python import pynotify import time import datetime c='5/1/12 1:15
The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite;
How do I import this database correctly? https://github.com/samanz/cakecart Every time I import then I
at the start and end of my program, I have from time import strftime
I have the following code which is executed from the command line: import cgi,time,os,json,sys,zipfile,urllib2
import socket from time import strftime time = strftime(%H:%M:%S) irc = 'irc.tormented-box.net' port =
When I run the script: import socket from time import strftime time = strftime(%H:%M:%S)
I'm using the following to get utc datetime: import datetime import time from pytz

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.