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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:29:09+00:00 2026-06-16T10:29:09+00:00

I am using DateTime module. however it is providing wrong time. Please consider below

  • 0

I am using DateTime module. however it is providing wrong time. Please consider below code:

#!/usr/bin/perl -w
use strict;

use Time::localtime;
my $now = ctime();
print $now."\n";

print "------------------------------\n";

use DateTime;
my $dt = DateTime->now;
print $dt."\n";

And its output is:

Wed Dec 26 22:11:52 2012
------------------------------
2012-12-27T06:11:52

so, As you can see, the DateTime output is leading by 8 hours which is wrong. Here is the Linux date command output:

# date
Wed Dec 26 22:13:17 PST 2012

So, the date command output matches with that of time::localtime output.

could you help me understand where I am going wrong in using DateTime module.

-Thanks.

UPDATE:

from hte CPAN documentation:

DateTime->now( ... )

This class method is equivalent to calling from_epoch() with the value returned from Perl's time() function. Just as with the new() method, it accepts "time_zone" and "locale" parameters.

By default, the returned object will be in the UTC time zone.

So, It seems that the time returned is in UTC. However, the timezone I am in in PST. Probably thats why I see the different time.

  • 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-16T10:29:11+00:00Added an answer on June 16, 2026 at 10:29 am

    I passed the zone info and it works perfectly now:

    #!/usr/bin/perl -w
    use strict;
    
    use Time::localtime;
    my $now = ctime();
    print $now."\n";
    
    print "------------------------------\n";
    
    use DateTime;
    my $dt = DateTime->now ( time_zone => 'America/Los_Angeles' );
    print $dt."\n";
    

    Output:

    Wed Dec 26 22:28:44 2012
    ------------------------------
    2012-12-26T22:28:44
    

    For East Coast

    my $dateF = DateTime->now( time_zone => 'America/New_York' )->ymd;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the DateTime Perl module to get the time in a particular timezone.
I am using datetime.fromtimestamp to convert epoch time into local time. I found that
Using import datetime in python, is it possible to take a formatted time/date string
I am trying to use datetime module. I need the month to come back
I'm using the sqlite3 module in Python 2.6.4 to store a datetime in a
How to get the first and last second in python using the DateTime module
I'm using the matplotlib candlestick module which requires the time to be passed as
I'm trying to compare two times using the Python datetime module, but I can't
The time module can be initialized using seconds since epoch: import time t1 =
I'm using the datetime module, i.e.: >>> import datetime >>> today = datetime.datetime.now() >>>

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.