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

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

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')

How to convert "12/20/2018 1:30 AM" format to the YY-MM-DD hh:mm:ss in angular js?

I have to store the date in the database using this format YY-MM-DD hh:mm:ss but I get this 12/20/2018 1:30 AM after select date from the kendo-datetime picker.
I have tried fomat="YY-MM-SS hh:mm:ss" but its not working every time getting above the same format.
Tell me, anyone, how to convert selected date and time to YY-MM-DD hh:mm:ss?
var date = object.dTime;
var newdate = date.split("/").reverse().join("-");
Use moment library in order to format the date into whatever way that you want to display,
moment(date).format('YY-MM-SS hh:mm:ss')
For more detail, look at here
You can use in angular moment js please read moment js implementation.
or you can follow this link both question are something same .
[format date with moment.js
In your html file use this
<input kendo-date-picker
k-format="'dd/MM/yyyy'"
ng-model="model.Date"
name="Date" required />
var date = new Date('12/20/2018 1:30 AM')
date.toISOString().replace('T', ' ').substring(2, 11) + date.toTimeString().substring(0, 8) // "18-12-19 01:30:00"

Parse polish date with time to ISO format in 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

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');

How to convert date format in JavaScript?

In my Rails application, in JSON responses from controller, dates are coming as 2015-06-22T18:08:22+05:30. I want to convert the date into 22-06-2015, 06:08 PM format in Javascript. I checked may resources in Stackoverflow but none is working. Is there any way to do that?
you can use date.format library
Here's a example fiddle
var date = new Date("2015-06-22T18:08:22+05:30");
var dateString = date.format("dd-mm-yyyy hh:MM:ss TT Z");
alert(dateString);
Also it would be better to format it on server side if you dont want to include extra libraries
moment is a very good library for dealing with date.
console.log(moment('2015-06-22T18:08:22+05:30').format('DD-MM-YYYY h:mm:ss a'));
> 22-06-2015 7:38:22 pm
There are Two Ways:
Do the conversion in the Rails and send the value via JSON (using strftime or u can use Date.strptime or Time.strptime)
Code:
User.created_at.strftime("%d/%m/%Y")
Doing the conversion in Front End using Moment Js:
Code:
console.log(moment('2015-06-22T18:08:22+05:30').format('DD-MM-YYYY h:mm:ss a'));

Categories