Parse polish date with time to ISO format in Javascript - javascript

I have date 14.05.2017 15:32 its polish format of date and time dd.MM.yyyy HH:mm when im using moment library with locales it always set time to default value of 00:00:00.
Here is example code that i've tried to use
Fiddle
console.log(moment('14.05.2017 15:32').format('dd.MM.yyyy HH:mm'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.3/moment.min.js"></script>
Any other suggestions how to parse it?
Expected result:
2017-05-14T15:32:00.004Z

You should replace the 'pl' argument with the explicit format to parse and add the argument to the format method to display it in the same format:
moment('14.05.2017 15:32','DD.MM.YYYY HH:mm').format('DD.MM.YYYY HH:mm')
Fiddle here

Related

how modify date format using momentjs

What is the proper way to get below date format using moment.js,
29-OCT-2022 02.10.01.516000000 AM
I tried the below-mentioned code
DD/mm/yyyy HH:mm:ss
Try this
moment().format('Do-MMM-YYYY hh.mm.ss A')

Why date is mismatch in JavaScript while conversion?

Why date is mismatch in javascript .I am getting this millisecond “-2208988800000” .I converted this using moment like this
moment(new Date(-2208988800000).toUTCString()).format('DD-MMM-YYYY')
Which give output “01-Jan-1900"” (which is correct)
Now I try to get again same long value or millisecond
moment(new Date("01-Jan-1900")).format('x')
"-2209008070000"
Why is mismatch in value ? "-2209008070000" and "-2208988800000" is not same
new Date("01-Jan-1900") is not something that works in every browser. Firefox for example outputs Invalid Date. The Date constructor has lots of quirks, and it's exactly why you should use a library like Moment.js to parse date and time strings.
Refer to the MDN documentation on Date and new Date(dateString) for additional details.
I think you are losing hours while converting to DD-MMM-YYYY
console.log(moment(new Date(-2208988800000).toUTCString()).format('DD-MMM-YYYY HH:mm:ss'))
//output of above line is input to below.
console.log(moment.parseZone(new Date("31-Dec-1899 19:00:00")).format('x'))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://momentjs.com/downloads/moment.js"></script>

How to Convert epoch this format "MM/DD/YYYYHH:mm:ss"

i select calendar and set "1517380775843" console , i try convert and get format = 20180131093935 GMT+03:00 ,not now time i try select time and convert to human readable data pls help . thanks
<DateTimeField onChange={this.clock} format={"x"} inputFormat={"YYYY/DD/MM HH:mm:ss"}/>
clock=(newDate)=>{
console.log(newDate)
}
Use moment JS to do such operations.
For example:
moment.parseZone(element.requestDate).format('DD-MM-YYYY hh:mm A')
or for converting to a format specified:
moment(dateString,'DD-MM-YYYY hh:mm A')
Visit https://momentjs.com/ for the docs

Unable to parse date from dd-mm-yyyy format to yyyy-mm-dd using moment.js

i am using moment.js to parse date , following is the date that i am passing as input 16-11-2017 and i want it to be 2017-11-16
selected_date = moment(selected_date).format('YYYY-MM-DD');
console.log(selected_date);
I am getting invalid date when i parse, please refer to image below.
Have you tried giving the format of the original date
moment(selected_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
Try this
selected_date = moment(selected_date, 'DD-MM-YYYY').format('YYYY-MM-DD');
You need to tell moment the input format if it is not in a recognised format.
Try
moment(selected_date, 'DD-MM-YYYY').format('YYYY-MM-DD');

Apply filter for date failing in Angular JS

I'm getting date from a rest service as
$scope.dob="1989-10-17 00:00:00"
How can I convert /apply filter to this date to look like normal date (without time).
I tried with splicing the time part but this is inside ng-repeat.It's not working
Please note the format date filter understands:
Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
"1989-10-17 00:00:00" can't be parsed. Instead it should be: "1989-10-17T00:00:00Z"

Categories