


A brief discussion on Date (date object) and Math object in JavaScript_javascript skills
Date object
1. What is a Date object?
Date objects can store any date and can be accurate to milliseconds (1/1000 of a second).
Syntax: var Udate=new Date();
Note: The initial value is the current time (current computer system time).
2. Common methods of Date objects:
3.Date method instance
var newTime=new Date();//Get the current time
var millSecond=Date.now();//The number of milliseconds converted from the current date
var fullYear=newTime.getFullYear();//Get the year
var year=newTime.getYear();//Get the year
var month=newTime.getMonth();//Get the month, return 0-11 0 means January, 11 means December
var week=newTime.getDay();//Get the day of the week Returns a number from 0-6, 0 means Sunday
var today=newTime.getDate();//Get today’s date
var hours=newTime.getHours();//Get the hours
var minutes=newTime.getMinutes();//Get the minutes
var seconds=newTime.getSeconds();//Get seconds
console.log(newTime);// Wed Feb 04 2015 10:54:17 GMT 0800 (China Standard Time)
console.log(millSecond);// 1423029309565
console.log(fullYear);// 2015
console.log(year);//115
console.log(month);//1 means February
console.log(week);//3 means Wednesday
console.log(today);//4 No. 4
console.log(hours);//10 hours
console.log(minutes);//54 minutes
console.log(seconds);//17 seconds
Math object
1. What is a Math object ?
Math object, providing mathematical calculations on data.
Note: The Math object is an inherent object. There is no need to create it. You can call all its properties and methods by directly using Math as an object. This is the difference between it and Date and String objects.
2. Properties and methods of Math object
Math object properties
Math object methods
3. Individual method instances of Math object
1): The ceil() method rounds up and returns the integer that is greater than or equal to x and is closest to x.
document.write(Math.ceil(0.8) "
")//1
document.write(Math.ceil(6.3) "
")//7
document.write(Math.ceil(5) "
")//5
document.write(Math.ceil(3.5) "
")//4
document.write(Math.ceil(-5.1) "
")//-5
document.write(Math.ceil(-5.9))//-5
2): The floor() method rounds down and returns the integer that is less than or equal to x and the closest to x.
document.write(Math.floor(0.8) "
")//0
document.write(Math.floor(6.3) "
")//6
document.write(Math.floor(5) "
")//5
document.write(Math.floor(3.5) "
")//3
document.write(Math.floor(-5.1) "
")//-6
document.write(Math.floor(-5.9))//-6
3): The round() method can round a number to the nearest integer
document.write(Math.round(0.8) "
")//1
document.write(Math.round(6.3) "
")//6
document.write(Math.round(5) "
")//5
document.write(Math.round(3.5) "
")//4
document.write(Math.round(-5.1) "
")//-5
document.write(Math.round(-5.9) "
")//-6
4): The random() method can return a random number between 0 ~ 1 (greater than or equal to 0 but less than 1).
document.write(Math.random());//Returns a number between 0 and 1, excluding 1
document.write(Math.random()*10);//Returns a number between 0 and 10, excluding 10
5): min() method: returns the minimum value in a set of values
document.write(Math.min(2,3,4,6));//2
To get the minimum value in the array, use the apply() method:
var values=[3,2,1,8,9,7];
document.write(Math.min.apply(Math,values) "
");//1
Math object as the first parameter of apply, and any array as the second parameter
6): max() method: returns the maximum value in a set of values
document.write(Math.max(2,3,4,6));//6
To get the minimum value in the array, use the apply() method:
var values=[3,2,1,8,9,7];
document.write(Math.max.apply(Math,values) "
");//9
The above is all about Date (date object) and Math objects in JavaScript. I hope you like it.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools
