Search code examples
phplaravelphp-carbon

How to convert any time zone into UTC using Laravel


I want to convert the user's time, eg. 08:45 P.M, to UTC time zone. How can I do that?

if ($request->open_at)
{
  $time = Carbon::parse($request->open_at)->toUTCString();
  dd($time);
  $query->whereTime('open_at', '>=', $time);
}

Solution

  • Use this PHP approach:

    $time = new DateTime("08:45 P.M");
    $time ->setTimezone(new DateTimeZone("UTC"));
    echo $time ->format("Y-m-d H:i:s e");