I'm using angularjs and mongodb.
I have not found a angularjs date slider so I'm taking this one. The idea is to use a timestamp with a step a day. So I take this timestamp convert it to a dd mmmm yyyy format and be displayed in the front-end.
Assuming as I said I use mongodb what can be a good solution for the date number format?
If you are looking for a date time library, try moment.js
It is very simple to use. Include the script file using <script> tag. Then use it like this.
moment().format('MMMM Do YYYY, h:mm:ss a');
This will return November 6th 2013, 1:35:00 pm
If you need to show the time in human format use fromNow() like this moment("20111031", "YYYYMMDD").fromNow(); This will result 2 years ago .
Related
I have date in this format:
2022-06-28T17:09:00.922108+01:00
I want to covert it into a more readable format.
I'm using javascript/react and I tried moment-js but it gives me "invalid format".
What are my other options of turning it into a normal date?
You can use this to format date:
const format = "DD-MM-YYYY"
moment(date).format(format)
or
moment().format('MMMM Do YYYY, h:mm:ss a'); // June 28th 2022, 9:49:49 pm
for more detail refer: https://momentjs.com/
If you are using moment.js you can convert this to any format you like using this doc
Sample code
moment('2022-06-28T17:09:00.922108+01:00').format("DD-MM-YYYY"); //28-06-2022
Kindly go though the moment.js features and documents. There is a lot more you can do with this like showing time, day of the week etc
In this example on CodeSandbox I'm trying to get the date formatted as dddd, MMMM Do and the expected result should be like Thursday, January 13th but instead is 0013, January 13th
As per date-fns documentation here Date-fns format, writing dddd should give me back the name of the day but I got instead 0013 and I don't understand why.
I need help on what is wrong with the way I'm writing the date format and get the name of the day instead of that 0013.
You are using a new version of date-fns https://date-fns.org/v2.16.1/docs/format.
You may use format="iiii, MMMM Do".
I have a date format like 2015-12-07T02:45:00.000Z but want to convert it to like Nove 12 , 2015 4:30 PM or 3 minuts ago accordingly
You can use a library called moment.js. And use
moment().format('MMMM Do YYYY, h:mm a') to convert to your format or
moment().startOf('hour').fromNow() to print out relative time.
Have you looked at moment.js? It has relative conversions which seem to be what you are looking for.
Hey using ionic + cordova, when I fetch the selected contact with birthdate, date values comes into this formate (1424779200000). I know its correct value, but now I want to convert this value into date and display into my application. I don't want to write any native code for everyone (like ios, android...). Is there any javascript for this....?
use moment.js (http://momentjs.com/)
e.g.
moment(yourVal).format('MMMM Do YYYY, h:mm:ss a'); // February 24th 2015, 11:54:41 am
How to split the below date format into day date and time.
Date Format is like "2013-05-07T11:04:00+05:30"
I want to display above date like "Tue,7 May 2013, 11.04AM".
Please suggest how to do this in java script or jquery
Thanks in Advance.
You can use this very useful little library:
http://momentjs.com/
Example:
moment("2013-05-07T11:04:00+05:30", "MMMM Do YYYY, h:mm:ss a");
You might be able to use Date.parse(string), but there is no way to determine what date/time formats a particular JavaScript implementation supports.
Otherwise:
Use a regex to break up (and validate) the string, convert each string component into a Number and then pass to the Date constructor taking separate components.
Use a library that implements the previous option (eg. see other answer).
You should work with the native Date Object - this is the easiest way to handle the string.
You can do the following:
var date = new Date("2013-05-07T11:04:00+05:30");
now you have several Date methods you can use to format your string and get the information you need, e.g. what you want is:
date.toUTCString()
// output:
"Tue, 07 May 2013 05:34:00 GMT"
You also could use a regex or an external library, but probably the best way (imo!) is to simply work with the Date Object.
moment.js could be a good choice for you, for example:
Actual moment:
moment().format('MMMM Do YYYY, h:mm:ss a');
Format:
moment("2013-05-07T11:04:00+05:30", "MMMM Do YYYY, h:mm:ss a");