Skip to content
Advertisement

Tag: date

JavaScript date variable is returning incorrect dates for string input

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

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

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

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

Advertisement