I have my indian standard time like ,
Wed Oct 08 2014 07:40:00 GMT 0530 (India Standard Time) , which is created by javascript,
Now i want to change this format to 2014-11-10 07:40:00 to store in mysql.
how can i do this.
I hope this will help you
$date = "Wed Oct 08 2014 07:40:00";
echo date('Y-m-d h:i:s',strtotime($date));
output
2014-10-08 07:40:00
You can use the moment.js library.
var a = "Wed Oct 08 2014 07:40:00 GMT 0530 (India Standard Time)";
var b = moment(a).zone(0).format(YYYY-MM-DD HH:mm:ss);
I personally would transform your time with the time()-function to the unix format amd with then with date() back to your liking:
http://php.net/manual/de/function.date.php
i.g.: date('Y-m-d H:i:s',time()) would give you the momentary time in the desired format.
edit: I forget the damn '...', but I corrected that. The accepted answer ist correct and a little bit better than mine.
Related
i am using moment js with my project and parsing the normal date string for example ("21-jun-2020"). However the parse result is different in chrome and firefox
For chrome
_d: Mon Jun 21 2021 00:00:00 GMT+0530 (India Standard Time)
For Firefox
_d: Date Thu Jun 21 -2021 00:00:00 GMT+0553 (India Standard Time)
Is there any way to get a constant result on both the browsers.
You can parse it to UTC to have constant result
moment("2010-10-20 4:30").utc()
or using unix timestamp
var day = moment.unix(1318781876).utc();
moment("2010-10-20 4:30").unix()
I'm using some library that won't sort objects by a string value but will sort them by date. I have months like '2008-04' and I should be able to convert them to Javascript dates for the first of the appropriate month. But my local timezone screws things up:
new Date('2008-04')
Mon Mar 31 2008 20:00:00 GMT-0400 (EDT)
This is probably a duplicate of How do you convert a JavaScript date to UTC?, but maybe there's a simpler answer for my particular use case than the ones there?
BTW, I get the same answer by specifying the first of the month:
new Date('2008-04-01')
Mon Mar 31 2008 20:00:00 GMT-0400 (EDT)
I'm using ES6. I don't suppose that makes it any more straightforward?
Add '-01T00:00:00Z' to the string with part of ISO 6801 date:
document.write(new Date('2008-04' + '-01T00:00:00Z'));
I misunderstood. The date is already UTC, it's just when I display it as a string locally that it gets converted to my local timezone. So the answer is just
new Date('2008-04').toUTCString()
"Tue, 01 Apr 2008 00:00:00 GMT"
or
new Date('2008-04').toISOString()
"2008-04-01T00:00:00.000Z"
I am using bootstrap calendar and on clicking any particular date I got complicated date in this form:
Sat Sep 06 2014 00:00:00 GMT 0500 (Pakistan Standard Time)
Can anybody please tell me how I can extract only date from this complicated long date?
I am working in PHP codeignitor, is there any way in PHP or JavaScript through which I can only extract date?
if this is for Javascript then just use this:
var myDate = new Date('Sat Sep 06 2014 00:00:00 GMT 0500 (Pakistan Standard Time)');
after that you can use myDate as a date object and call its methods like myDate.getFullYear() etc.
The input that am giving for my javascript function is
`Wed Jul 30 2014 11:34:00 GMT+0530 (India Standard Time)`
the fucntion that need to return this in to my needed fomat i.e
July 30 2014 11:34 AM
How can i achieve this?
Maybe Moment.js helps you?
Check this answer
I have Date String Thu May 23 2013 18:19:32 GMT+0530 (India Standard Time) from my database. I want to make in this format THURSDAY May 23 2013 18:19:32 GMT 0500 CDT in ext-js.any idea ? Thanks in advance.
There are 2 excellent ate parsing libraries available tat you can use. They are both very small
https://code.google.com/p/datejs/
http://momentjs.com/
Sample datejs usage:
Date.parse('Thu, 1 July 2004 22:30:00 GMT') // Thu Jul 01 2004 16:30:00
You can then format the date object in whatever format you require for output.