convert string into datetime by using javascript? - javascript

My string is like 3/29/2016 17:30.How to convert it into datetime in javascript?
and I want to compare it with another date?

var date= new Date("2016-03-29 17:30:00".replace(/-/g,"/"));
if date is dynamic then you have to break that using substring method and concat in above format.

Related

How do I convert a LocalDateTime to a JavaScript Date object with JS-Joda?

how do I convert a LocalDateTime Object from the #js-joda/core library to a standard JavaScript Date object?
As #RobG mentioned in a comment import convert from '#js-joda/core' and you can use let date = convert(ZonedDateTime.now()).toDate(); to get a js date

How to format dates with Pentaho Spoon

How do I convert the string 03-MAR-2021 to the string 20210303 with Javascript in Pentaho Spoon
start_date="03-MAR-21";
var new_startDate= new Date(start_date);
var date= moment(new_startDate).format('yyyyMMdd');
See common date formats
start_date="03-MAR-2021";
var date= str2date(start_date, "dd-MMM-yyyy");
var formatedDateString = date2str(date, "yyyyMMdd");
I get the date in a string like '03-Mar-2021' but I need to convert to string '20210303' (YYYYMMDD) I can make in JScript or directly on Query. But I have problems when I try to

Changing date format to a specific format in JavaScript

In my application I have date coming in an ISO String format: '2020-12-20T15:21:28.411Z'
In the database the value is stored as: '2020-12-20 15:21:28+411'.
So how can I convert '2020-12-20T15:21:28.411Z' -> '2020-12-20 15:21:28+411'.
I don't want to use moment.js and .toLocaleString() does not work.
Assuming your date is in the string format, you can replace the dot with a + and the T with a space, then chop off the last character:
yourDate.replace(/\./g,"+").replace(/T/g," ").slice(0,-1)

How to convert date time string in formatted date time in extjs

I have a string of Date and Time ("2017-11-29 11:08:43" YYYY-MM-DD hh:mm:ss) like this. I want to convert it into "29-11 11:08"(DD-MM hh:mm) format.
I tried it using below code. But not get any success. have you any solution?
convert: function (idleFrom) {
var date = Ext.Date.parse(idleFrom, "Y-m-d");
return date;
}
first change your string into date format using
var dt = new Date(idleFrom)
than change into you required format using
Ext.Date.format(dt, 'm/d/Y');
follw this link for more format
Hope it will work :)
If you have a string, and want it reformatted, you have to parse the string into a JS date object first, and then format the JS date object into the string representation you need:
var date = Ext.Date.parse("2017-11-29 11:08:43", "Y-m-d H:i:s")
var str = Ext.Date.format(date, "m/d/Y")
Please note that Ext.Date.parse is really picky regarding the format identifier. If the matching between the format identifier and the input string's format is not 100%, your date will be null.
E.g. Ext.Date.parse("2017-11-29 11:08:43", "Y-m-d H:i") will be null because the seconds are in the date string, but missing from the format identifier.

Convert string to ISODate

How could I convert the string "2015-02-02" to ISODate 2015-02-02T00:00:00.000Z? I was trying to find some example but did not.
You can use the regular Javascript date functionality for this
new Date(dateString).toISOString()
from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
However, date parsing is very inconsistent across browsers so if you need this to be robust I would look into parsing using for example with Moment.js as this will allow you to specify a format string by which the date should be parsed like such
date = moment("12-25-1995", "YYYY-MM-DD");
date.format(); //will return an ISO representation of the date
from: http://momentjs.com/docs/#/parsing/string/
To change "2015-02-02" to "2015-02-02T00:00:00.000Z" simply append "T00:00:00.000Z":
console.log('2015-02-02' + 'T00:00:00.000Z');
Parsing to a Date and calling toISOString will fail in browsers that don't correctly parse ISO dates and those that don't have toISOString.
new Date("2015-02-02").toISOString()
new Date("11/11/2019").toISOString()
or use it as a variable
mydate = "11/11/2019"
new Date(mydate).toISOString()

Categories

Resources