This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I Convert DateTime.now to UTC in Ruby?
How do I get current time in Date-time-milliseconds & UTC?
Ex. 2012-03-22T18:48:40.873Z
I tried -
Time.now.utc_offset.to_s
Time.now.xs_datetime
Time.now.utc is what you must be using.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
My request returns a date string
"07/13/2020 8:00 AM - 07/17/2020 5:00 PM"
Then I explode it
$datetimes = explode(' - ', $request->datetimes);
Then I get when I DD
"07/13/2020 8:00 AM"
When I use carbon to format the string
\Carbon\Carbon::parse($datetimes[0])->format('d M, H:mA')
It returns
"13 Jul, 08:07AM"
Why is this happening?
Because it's converting the date from the american format MM/DD/YYYY instead of the common DD/MM/YYYY
That why when handeling date formats, it's safer to use the mysql date format YYYY/MM/DD
it's how strtotime in php works, if the day is a valid month, it will use the MM/DD/YYYY format.
one easy trick is to replace the / with - to force it.
\Carbon\Carbon::parse(str_replace('/', '-', $datetimes[0]))
I was using "m" for month instead of "i" for minutes...
Can you please give this a try
Route::get('convert',function(){
$myString = "07/13/2020 8:00 AM - 07/17/2020 5:00 PM";
$dateTimes = explode(' - ', $myString);
$paseDateTime = \Carbon\Carbon::createFromFormat('m/d/Y g:iA',$dateTimes[0])->addMinutes(7)->format('m/d/Y g:iA');
return $paseDateTime;
});
Output
07/13/2020 8:07AM
This question already has answers here:
Use an array in Laravel update query
(3 answers)
Closed 1 year ago.
Customer::where('id'=>[5,6,7])->update(['name' => "Ashutosh"]);
Try like this:
Customer::whereIn('id', [5,6,7])->update(['name' => "Ashutosh"]);
You can found in docs about whereIn.
This question already has answers here:
Parsing date/time strings which are not 'standard' formats
(4 answers)
Closed 7 years ago.
I have format string "day/month/year, hour:minute:second"
How do I parse into a time object?
I tried:
const longForm = "5/01/2015, 12:00:00"
t1, _ := time.Parse(longForm, "5/01/2015, 12:00:00")
0001-01-01 00:00:00 +0000 UTC
I get some UTC time, but this is not helpful if I want to compare times because I get the same UTC time for them all. Any help?
Rule #1 of fightclub, err Go, check your errors.
That being said, the format for time parsing is defined in the documentation (scroll down to constants).
For your specific question, the format is 1/_2/2006, 15:04:05.
playground
This question already has answers here:
How do you calculate the day of the year for a specific date in Objective-C?
(6 answers)
Closed 9 years ago.
I need to know day of year with iOS sdk. I can do that manually, but wanted to know that is there any method to find day of year? I am not meaning that - How many days in a year. I need to know the number of day for a input date?
Got answer :) please see the below example
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
NSDate *today = [NSDate date];
NSInteger dc = [currentCalendar ordinalityOfUnit:NSDayCalendarUnit
inUnit:NSYearCalendarUnit
forDate:today];
NSLog(#"%d",dc);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Ruby - Change string in a date format to another format
My date format : 09/28/2012 16:35:34, I want the date to be formatted like: 2012-09-28T16:35:34, I need to compile the code in jruby.
You probably want to convert the date to something more useful:
require 'date'
dt = DateTime.strptime "09/28/2012 16:35:34", '%m/%d/%Y %H:%M:%S'
# => #<DateTime: 2012-09-28T16:35:34+00:00 (106107805067/43200,0/1,2299161)>
Now you can do any transformation:
dt.strftime '%FT%T'
# => "2012-09-28T16:35:34"
This also raises an exception when the date format is wrong, which is useful to notice when things break.
For more Information see the Apidocs for Date.
Find
(\d+)\/(\d+)\/(\d+) ([\d:]+)
replace with
$3-$1-$2T$4
Here you can see the groups (which in the regex are the parts in ()), $1 is the first group, $2 the second and so on. Basically you need to reorder the groups putting - in the middle and T before the hour.