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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:12:55+00:00 2026-06-09T09:12:55+00:00

I get the Error sometime on Converting 12hour format time from a Timezone to

  • 0

I get the Error sometime on Converting 12hour format time from a Timezone to new
TimeZone

Error:

Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (00:00:31 AM) at position 9 (A): The timezone could not be found in the database' in C:\xampp\php\udp.php:105
Stack trace:
#0 C:\xampp\php\udp.php(105): DateTime->__construct('00:00:31 AM', Object(DateTimeZone))
#1 {main}  thrown in C:\xampp\php\udp.php on line 105

MyCodes:

// $gps_time = "9:43:52"; 
$gps_time      = $time_hour.":".$time_min.":".$time_sec;
// $time_received = "01:45:04 2012-07-28"; 
$time_received = date('H:i:s Y-m-d');

$utc = new DateTimeZone("UTC"); 
$moscow = new DateTimeZone("Europe/Moscow"); 

//Instantiate both AM and PM versions of your time 
$gps_time_am = new DateTime("$gps_time AM", $utc); 
$gps_time_pm = new DateTime("$gps_time PM", $utc); 

//Received time 
$time_received = new DateTime($time_received, $moscow); 

//Change timezone to Moscow 
$gps_time_am->setTimezone($moscow); 
$gps_time_pm->setTimezone($moscow); 

//Check the difference in hours. If it's less than 1 hour difference, it's the correct one. 
if ($time_received->diff($gps_time_pm)->h < 1) { 

$correct_time = $gps_time_pm->format("H:i:s Y-m-d");
} 
else { 

$correct_time = $gps_time_am->format("H:i:s Y-m-d");
}

echo $correct_time;

Question: Where’s the problem !!?
P.S: above Code is a part of my udp socket and run from php cli

  • 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-09T09:12:57+00:00Added an answer on June 9, 2026 at 9:12 am

    Summary

    Put simply, that PHP is trying (mistakenly, for your needs) to read AM as a timezone and AM is not a valid timezone.


    Details

    10:39:6 AM gets separated into the following pieces

    • 10:39:6 it recognises as timelong24 (a 24-hour formatted time with seconds)
    • AM it recognises as tz (timezone).

    In contrast, for 10:39:06 AM it correctly parses the whole string as timelong12 (a 12-hour formatted time with seconds and AM/PM).

    Boring bit

    The reason for this strange behaviour lies in the date parsing logic (source). The relevant patterns are:

    timelong24

    't'?
    [01]?[0-9] | "2"[0-4]              # hour24
    [:.]
    [0-5]?[0-9]                        # minute
    [:.]
    [0-5]?[0-9] | "60"                 # second;
    

    timelong12

    "0"?[1-9] | "1"[0-2]               # hour12
    [:.]
    [0-5]?[0-9]                        # minute
    [:.]
    [0-5][0-9] | "60"                  # secondlz
    [ \t]*                             # space?
    ([AaPp] "."? [Mm] "."?) [\000\t ]  # meridian;
    

    As you can see, to match the timelong12 format (which is what we really wanted), the seconds portion of the time must be double-digits.

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

Sidebar

Related Questions

I sometime get following error message: Cannot convert the value in attribute 'Color' to
I'm trying to send a message and we sometime get this error : Service
I get this error sometimes, Catchable fatal error: Object of class stdClass could not
Every now and then I sometime get the following error A component named dlgPrinterSettings
When i ssh to a machine, sometime i get this error warning and it
I get this error sometimes reported when creating a dialog, i haven't experienced the
sometimes i get an error like table is marked as corrupt and shld be
In Ruby on Rails, I sometimes get an error on the page as: compile
Sometimes when I am inside my app, I get the following error : java.io.IOException:
Sometimes users mistakenly redirected to ?Process=ViewImages&PAGEID=. When this happens, they get the following error.

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.