php-carbon

How to set Laravel Carbon timezone for timestamps?

对着背影说爱祢 提交于 2020-01-12 14:13:49
问题 I have a project which is primarily based in CET region. I set CET in config/app.php, but all pivot timestamps in the base are stored in UTC time? How can I set "global" timezone for timestamps? i made this test: <?php $timezone = date_default_timezone_get(); echo "The current server timezone is: " . $timezone; echo "<br />".date('m/d/Y h:i:s a', time()); $mytime = Carbon\Carbon::now(); echo "<br />".$mytime->toDateTimeString(); ?> and here's the result: The current server timezone is: CET 06

Bad characters in utf-8 Carbon formatLocalized

南楼画角 提交于 2020-01-05 05:58:43
问题 I know there is much about this, but it doesn't work, I have the language installed. locale -a | grep es es_ES es_ES.ISO8859-1 es_ES.ISO8859-15 es_ES.UTF-8 I have set to utf-8 \Carbon\Carbon::setUtf8(true); setlocale(LC_ALL, 'es_ES.UTF-8'); $game_date = $date->formatLocalized('%A %d %B %Y %H %M %p'); I have the utf-8 tag in my html <meta charset="utf-8"> but I am still getting the wrong characters. "sábado" - "miércoles" 回答1: I had the same problem when trying to use the sk_SK.UTF-8 locale.

Carbon now time wrong

故事扮演 提交于 2020-01-03 07:18:06
问题 I just started using the Carbon extension (seems pretty sweet so far), but am confused on the Carbon::now() function. According to the docs, it seems as though this function should reflect the current time in the users current timezone, however, I seem to get a time that is an hour ahead of GMT. i.e. Carbon::now() says 2015-01-01 17:26:46 when I am on PST and it is actually currently 2015-01-01 08:26:46 . Do I have to detect and put in a users local timezone for all instances? What gives? (I

Format Timezone for Carbon Date

本小妞迷上赌 提交于 2020-01-01 03:54:08
问题 I'm trying to set the timezone for a date in a Carbon object. It works fine locally but on my production box it keeps giving me Bad timezone error. I've tried: $date->setTimezone('7'); $date->setTimezone('+7'); $date->setTimezone('7:00'); $date->setTimezone('+7:00'); $date->setTimezone('UTC 7'); $date->setTimezone('UTC +7'); $date->setTimezone('UTC 7:00'); $date->setTimezone('UTC +7:00'); No idea why it's complaining on my production box. Can't find documentation either on what is the "proper

PHP Carbon take number of minutes & convert to days

时光毁灭记忆、已成空白 提交于 2019-12-31 04:01:08
问题 I am trying to convert a number on minutes into number of days using Carbon. $minutes = 1400; I want to do something like below (which of course, does not work): Carbon->minutes($minutes)->days(); I cannot find an example of this. Thanks for any help. 回答1: Not tested, but a quick look at the docs suggests it might be aimed more at DateTime objects than differences in time, so you could do something like this: $now = Carbon::now(); $days = $now->diffInDays($now->copy()->addMinutes($minutes));

Get the 0-value timestamp date with Carbon

六月ゝ 毕业季﹏ 提交于 2019-12-31 00:29:40
问题 I am attempting to get the 0-value timestamp in an PHP API. I am currently using Carbon in a Laravel / Dingo API based system. Is there a simple way to get the 0-value timestamp (presumably something like 01/01/1970) without hardcoding the date? 回答1: You could try: echo Carbon::createFromTimestamp(0)->toDateString(); // Displays: 1970-01-01 So you do not have to hardcode the date, just use a 0 timestamp. 来源: https://stackoverflow.com/questions/43652282/get-the-0-value-timestamp-date-with

Displaying of month and it's year based on condition

馋奶兔 提交于 2019-12-25 07:59:12
问题 In my Laravel 5.1 application, I have a feature of Subscription. It is working to a certain extent, but not what I am looking for.. Scenario : A user makes a subscription on October 2016 for 6 months.. So, the array will look something like this: [ "subscription_months" => 6 "subscription_start_month" => "01-10-2016" // <-- will be carbon instance "subscription_end_month => "31-03-2017" // <-- will be carbon instance "monthName" => "October" ] The above array I am showing is only 1 month..

PHP converting UTC to Local Time

我与影子孤独终老i 提交于 2019-12-25 06:42:19
问题 In my postgresql, the I have the following column named "created" that has the type timestamp with timezone So I inserted the record according to the format as such which I believe is UTC. 2015-10-02 09:09:35+08 I am using php Carbon library so i did the following: $date = Carbon\Carbon::parse('2015-10-02 09:09:35+08'); echo $date->->toDatetimeString(); //gives result as 2015-10-02 09:09:35 How can I use the library to echo the correct timezone which includes the adding of the +8 in the above

Laravel / Carbon adding two timestamps together?

三世轮回 提交于 2019-12-25 06:13:11
问题 I am working on a system where people can start and stop something which calculates the time it has taken them. This is done by: When the "Start" button is pressed, a date is added into the database table for that row. When the "Stop" button is pressed, a date (end date)is added then I calculate the difference by: $startTime = \Carbon\Carbon::parse($task->date_start); $finishTime = \Carbon\Carbon::parse($task->date_complete); $totalDuration = $finishTime->diffInSeconds($startTime); And also

Carbon get month by number returns march for number 2

…衆ロ難τιáo~ 提交于 2019-12-25 02:16:46
问题 Has anyone ever had this bug before, or know a way to fix it? I want to get a list of all months in the current year (start date and end date) in an array, so i'm doing like this (open to suggestions for cleaner easier ways) //Create a months array $months = []; //Get start and end of all months for($i = 1; $i <= 12; $i++){ $array = []; $array['start'] = Carbon::create()->month($i)->startOfMonth()->format('d/m/y'); $array['end'] = Carbon::create()->month($i)->endOfMonth()->format('d/m/y');