Can anyone help me convert a date from this format:
22-07-2020 12:00
to the following format:
2020-07-07T11:39:02.287Z
I'm unsure how to achieve this, any advice would be appreciated. Thanks!
Can anyone help me convert a date from this format:
22-07-2020 12:00
to the following format:
2020-07-07T11:39:02.287Z
I'm unsure how to achieve this, any advice would be appreciated. Thanks!
Below is a handy function that converts a string containing date and time in the format YYYY-MM-DD hh:mm:ss
to an ISO date:
function toIsoDate(dateTime){
const date = dateTime.split(" ")[0].split("-");
const time = dateTime.split(" ")[1].split(":");
return new Date(date[2], date[1]-1, date[0], time[0], time[1]);
// or if you want to return ISO format as a string
return new Date(date[2], date[1]-1, date[0], time[0], time[1]).toISOString();
}
The Date
object accepts parameters in this order:
(year, month, day, hours, minutes, seconds, milliseconds)
. It's important to note that the value for the month parameter ranges from 0 to 11, not 1 to 12. That's why we subtract 1 from the month (date[1]
) within the function.
const dateTime = "22-07-2020 12:00";
console.log(toIsoDate(dateTime));
2020-07-22T12:00:00.000Z
Could someone please help me understand how to run this code smoothly without encountering any errors? var test = 'Something'; JSON.parse('{"xxx": test}'); I am inquiring about this because I have a JSON object containing variables th ...
I am just starting to learn about jquery and ajax, and I have a specific requirement to call ajax from a separate javascript function. The issue is that the JSP file is dynamically generated and the button IDs in the JSP file are also created using a for l ...
I'm a bit puzzled. The _layout.cshtml page I have below contains several bundles of .css and .js files. Upon the initial site load, each file in the bundles is processed, which makes sense. However, every time a new view is loaded, each line of code f ...
This question builds upon a previous inquiry raised on Stack Overflow: When considering approach number 3 (referred to as the "counter" method), how can we ensure that the function handleCompletion can access necessary data from startOtherAsync to perform ...
I'm feeling a bit puzzled about how the function(err, data) callback operates. Is the first argument always designated to handle errors? And what happens with the rest of the arguments in a scenario like function(x, y, z, a, b, c)? How exactly does ...
Upon examining my App, I found that it is structured as follows: var app = angular.module('cockpit', ['tenantService', 'ngMaterial', 'ngMdIcons']); The controller associated with my App appears like this: angula ...
I'm struggling to figure out how to pass a simple id parameter to my created resource. The service in question is: angular. module('shared.testUser'). factory('TestUser', ['$resource', function($resource) { ...
I'm having trouble displaying my EJS files as HTML. Whenever I try to access my EJS file, I receive a "Cannot GET /store.html" error message. if (process.env.NODE_ENV !== 'production') { require('dotenv').config() } const stri ...
I am faced with a nested JSON object that contains an array as one of its properties. Each item in the array is separated by a ';'. My goal is to use ';' as a delimiter to split each array item and make necessary changes. However, I am ...
Imagine this: With the help of this plugin, you can have a video playing as your site's favicon using the following code snippet: var favicon=new Favico(); var video=document.getElementById('videoId'); favicon.video(video); //stop favicon.v ...
I developed a feature on my express server that allows users to download a file easily. app.post("/download", (req, res) => { let file_name = req.body.name; res.download(path.join(__dirname, `files/${file_name}.mp3`), (err) => { ...
I am attempting to ensure this code only activates when the device window exceeds 960px and triggers when the window scrolls down 700px. The second condition is functioning as intended, but the first condition is not working properly. The code functions f ...
I have three buttons on my website, each with its own unique content that should display in a modal when clicked. However, I am experiencing an issue where regardless of which button I click, the same content from the last button added is displayed in the ...
After successfully running opencart on my local machine, I encountered some errors upon uploading it to the hosting/server. The specific error message is as follows: Uncaught TypeError: Cannot read property 'document' of null f.each.contents @ j ...
For my Django app, I have successfully created static pages without any ajax requests. However, I now want to add a dynamic subpage that can change its content without refreshing or reloading the entire page. Let me explain what I'm trying to achieve ...
I have been working on an Angular 4 application and using reactive forms. For one of my forms, I am trying to implement custom validation on a control after it has been initialized, based on whether a checkbox is checked or unchecked. CODE form.componen ...
Here's a snippet from my index.html file: <body> <select id="car"> <option value="TOYOTA">TOYOTA</option> <option value="BMW">BMW</option> </select> <input type=button id="get_btn" valu ...
Trying to implement the Node.js example shown in the data post request section (located towards the end here: https://cloud.google.com/bigquery/loading-data-post-request) has hit a snag when dealing with larger files. While the sample code functions proper ...
Here is an example of the array structure: var myarray = [ device1: [ name:device1 , variables: [ variable1: [ name: variable1, unit: "a unit", ...
I recently developed a Vue application and integrated firebase tools to deploy it on Firebase hosting. Initially, everything worked fine when I ran npm run build and firebase deploy. However, upon making changes and attempting to use commands like npm run ...