I am receiving a string containing a datetime from a web service that is formatted as dd/MMM/yyyy hh:mm:ss it is not possible to change the web service output to match this JavaScript applications needs. For the sake of simplicity I am replacing the web service data with hardcoded Strings that have their values below. dateOne is invalid (Used to be
Tag: date
Sort String Json Date
I am getting date values like that: “/Date(1560458281000)/” from an array of objects. I just want to order these dates by descending and ascending. I am open to any examples with pure JavaScript and/or moment.js By the way, hours and minutes are important. I will show it like 2014/10/29 4:50 This code doesn’t work. Answer You should be carefull with
Invalid date when parsing with locale it
I need to parse a date in the “it” locale with momentjs, and I’m doing this What I get is “invalid date” and I don’t understand why. Can you help me? Using the “en” locale (with the date written as 12/20/2018) all is ok Answer The below snippet will accomplish what you want. It takes moment’s date format for a
Compare date values “instantly” on user input
This question might be similar to this other question: HTML Comparing 2 Dates with Javascript But I don’t want to use a button, simply make it instant. I have 2 inputs of type date and I want to compare between them. Now the condition works perfectly, It compares the 2 dates and shows an error if the 2nd date is
How convert input type=”date” in a timestamp?
I need to convert an <input type=”date”> value in a timestamp. This is my HTML code: This field has a value that I have put like 25/10/2017 My jQuery code is: But this is not working… why not? Answer make a new Date() passing the value of your input as parameter, then call getTime(). here an example:
Change language of Datepicker of Material Angular 4
How to Change language of Datepicker of Material Angular? I can’t find in documentation for Angular material 2. Here is a plunkr https://plnkr.co/edit/unzlijtsHf3CPW4oL7bl?p=preview Answer
Using sinon to mock a date object
Here is my code: I need to get that startTime in my unit test. From knowing unit testing in a java perspective, I would approach this problem as How can I mock the new date constructor? and then How can I mock the toLocaleTimeString function call?. However, I’m not sure that that’s the way to approach this problem in javascript.
How to check time between range using javascript
I have the time value in HH:MM format. Hours are in 24 hours format. e.g. 14:30 I want to do a checking using two IF condition if the time value is between 05:00 to 22:00 if the time value is between 22:00 to 05:00 I am not sure how to do that. Answer Since times in HH:mm format can be
How can one create a dynamic copyright date without document.write() in JavaScript?
How can one fetch and print the current year without using document.write() in JavaScript? This is for a typical copyright line in the footer; e.g., © 2017 Stack Overflow. Right now I’m using the standard document.write() method. Answer Yes sure you can use an element: Add a link to your JS like so: And within this file you can do:
Moment.js compare two date thrown a warning
I have created a simple app, which need a date comparison. I used Moment.js, and I have tried on answer on this question: Compare two dates in JS Moment js date time comparison How to compare only date in moment.js But all of them not working for me. and now I use this code: But in the console it’s thrown