


Convert js string date yyyy-MM-dd to date sample code_javascript skills
Recently I encountered a problem, that is, when getting the date in the form and transmitting it to the background through json, the Date.parse(str) function reported an error under ff: NAN
After looking for some information, I found that the reason is The Date.parse() function has requirements for date format: For details, refer to the Date.parse function
For js operation date:
Create a date object:
var objDate=new Date([arguments list]);
The parameter forms are as follows:
view plainnew Date("month dd,yyyy hh:mm:ss");
new Date("month dd,yyyy");
new Date(yyyy,mth, dd,hh,mm,ss);
new Date(yyyy,mth,dd);
new Date(ms);
Description:
month: Represents the month name in English, from January to December
mth: Represents the month as an integer, from 0 (January) to 11 (December)
Content
dd: Represents the first day of the month Days, from 1 to 31
yyyy: Four-digit year
hh: Hours, from 0 (midnight) to 23 (11 p.m.)
mm: Minutes, from 0 to 59 Integer
ss: number of seconds, integer from 0 to 59
ms: number of milliseconds, an integer greater than or equal to 0, indicating the difference between the time to be created and GMT time January 1, 1970 number of milliseconds.
I found out:
The date construction in Javascript can also support new Date("yyyy/MM/dd"); where: MM is an integer representing the month from 0 (January) to 11 (December), so it is very convenient to use regular expressions to convert string dates.
Test code:
Output result:
Tue Feb 3 00: 00:00 UTC 0800 2009
Tue Feb 3 10:52:03 UTC 0800 2009
Tue Feb 3 00:00:00 UTC 0800 2009
Tue Feb 3 10:52:03 UTC 0800 2009
Tue Feb 3 00:00:00 UTC 0800 2009
Tue Feb 3 10:52:03 UTC 0800 2009
NaN
NaN
Tue Feb 3 00:00: 00 UTC 0800 2009
Tue Feb 3 00:00:00 UTC 0800 2009
Tue Feb 3 11:12:13 UTC 0800 2009
NaN
-------- -----------
window .onload=function(){
var dependentVal="2005-3-4";
//Convert to date based on date string
var regEx = new RegExp("\-","gi" ;
//parse requires the format of 2005/3/4
var milliseconds=Date.parse(dependedVal);
alert(milliseconds)
var dependentDate=new Date();
dependedDate .setTime(milliseconds);
var now = new Date();
//Pay attention to the brackets, priority issues, helplessness
alert("Years apart:" (now.getFullYear() - dependedDate.getFullYear()));
}
In fact, the date must be transmitted between the browser and the server through the millisecond value, otherwise a 400 error will be reported!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1. First open the mobile web browser, search for the Weibo web version, and click the avatar button in the upper left corner after entering. 2. Then click Settings in the upper right corner. 3. Click the version switching option in settings. 4. Then select the color version option in the version switch. 5. Click Search to enter the search page. 6. After entering the keywords, click Find People. 7. When the search completion interface appears, click Filter. 8. Finally, enter the specific date in the release time column and click Filter.

1. Let me first talk about the method I used at the beginning, maybe everyone is using it too. First, open [View]——]Remarks Template[. 2. A place where you can actually see the date after opening it. 3. Select it first and delete it. 4. After deleting, click [Close Master View]. 5. Open the print preview again and find that the date is still there. 6. In fact, this date was not deleted here. It should be in the [Handout Master]. Look at the picture below. 7. Delete the date after you find it. 8. Now when you open the preview and take a look, the date is no longer there. Note: In fact, this method is also very easy to remember, because the printed handouts are handouts, so you should look for the [Handout Master].

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

Title: How to determine whether a string ends with a specific character in Golang. In the Go language, sometimes we need to determine whether a string ends with a specific character. This is very common when processing strings. This article will introduce how to use the Go language to implement this function, and provide code examples for your reference. First, let's take a look at how to determine whether a string ends with a specified character in Golang. The characters in a string in Golang can be obtained through indexing, and the length of the string can be

How to check if a string starts with a specific character in Golang? When programming in Golang, you often encounter situations where you need to check whether a string begins with a specific character. To meet this requirement, we can use the functions provided by the strings package in Golang to achieve this. Next, we will introduce in detail how to use Golang to check whether a string starts with a specific character, with specific code examples. In Golang, we can use HasPrefix from the strings package

Excel software has very powerful data processing functions. We often use excel software to process various data. Sometimes when we enter a date in an excel cell, the date in excel changes to a pound sign. How can we display the data normally? Let’s take a look at the solution below. 1. First, we put the mouse on the column width line between columns AB, double-click and adjust the column width, as shown in the figure below. 2. After the column is widened, we find that numbers are displayed in the cells instead of dates. This is definitely incorrect. Then we should check the format of the cells, as shown in the figure below. 3. Click the "Number" option in the "Home" tab, and click "Other Number Format" in the drop-down menu, as shown in the figure below.

Go language is a powerful and flexible programming language that provides rich string processing functions, including string interception. In the Go language, we can use slices to intercept strings. Next, we will introduce in detail how to intercept strings in Go language, with specific code examples. 1. Use slicing to intercept a string. In the Go language, you can use slicing expressions to intercept a part of a string. The syntax of slice expression is as follows: slice:=str[start:end]where, s
