This example describes the way JavaScript formats a specified Date object. Share to everyone for your reference. Specifically as follows:
* * Format Date object: "2015-04-17 10:20:00"
* var dateobj = new Date ();
*/
function formartdate
Copy Code code as follows:
function Newdate (str) {str = str.split ('-');
var date = new Date ();
Date.setutcfullyear (Str[0], str[1]-1, str[2]);
Date.setutchours (0, 0, 0, 0);
return date;
}
So, in order to ensure compatibility in
This article is mainly on the JavaScript Date object format into a string implementation of the method is introduced in detail, the need for friends can come to the reference, I hope to help you. JavaScript provides the date format is too simple,
Date Object1. How to createvar New //The immediate return is now the current time return format(Day of the week, month and minute time zone)2. Formatting methods for datesDateobject.todatestring (); Return to day of the month and
1, Date.now ()
Date.now () is in ECMAScript 5
//prior to, use +new Date ()
//Get current time
var now = (typeof Date.now = = "Funct Ion "? Date.now (): +new Date ());
Alert ("Right now:" + now);
2, Date.parse () method
First is the string to date object
Uses the datetime strptime () method, specifying a date string and date format
def str_to_datetime (str,format= '%y-%m-%d%h:%m:%s.%f '):
'
string time converted to time object
:p Aram str: Time string
A function is a set of statements to complete a function, the function of JS is defined by the keyword function + function name + a set of parameters; functions can be called repeatedly after they are defined, often written as a function, using
1 //An extension to date that converts date to a string of the specified format2 //the Month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,3 //year (Y) can use 1-4 placeholders,
This article mainly aims to read data from the XML file, and then return the data to the page using a third-party plug-in for plotting, and provides a detailed solution, if you are interested, you may find it helpful.
Let's talk about this
This is a very special question.You can see that there are two variables, Val and val_t. Because of a "T", the result is really very different.respectively:Tue Oct 16:59:31 gmt+0800 (China Standard Time)Wed Oct 00:59:31 gmt+0800 (China Standard Time)
Implement the format () function of the Date object in JavaScript
Due to Web page display problems, it is often necessary to convert the date into a certain format, but the JavaScript scripting language is not provided to them officially.
Let's talk about this application scenario first.:
Read data from the XML file, and then return the data to the page using a third-party plug-in for plotting.
The data read in XML is of course a string type, and if you want to use the time mode
Common methods of JS Date ObjectCreating an Event Objectvar now = new Date (); The current time is returned by default in the case of no referenceGet yearvar y=now.getfullyear ();Get monthvar m=now.getmonth () +1;//returns 0-11Get Dayvar d=
all things in JavaScript are objects: strings, arrays, numbers, functions ...1, each object with properties and methodsJavaScript allows custom objects2. Custom ObjectsA. Define and create an object instanceB. Use a function to define the object,
In fact, there is no bug, but the JS date object to overflow time for their own processing.
First set your system time to January 31, 2013, this step is important, otherwise it may not occur, and then execute the following code
The
An extension to date that converts date to a string of the specified formatThe month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,Year (y) can use 1-4 placeholders, milliseconds (S) with only 1
Want to write a date of the addition and subtraction method, but it involves the judgment of the days of the month, if it is February, but also related to the judgment of leap years, some complex, the application process is always a problem, so
varMyDate =NewDate (); Mydate.getyear (); //get Current year (2-bit)mydate.getfullyear (); //Get the full year (4-bit, 1970-????) Mydate.getmonth (); //Get the current month (0-11, 0 for January)mydate.getdate (); //get current day
first of all, let's talk about the application scenario :
Read the data from the XML file, and then return the data inside to the page and draw with a third party plug-in.
The data that is read in XML is, of course, a string type, and if you want
/** * This JS file is formatted JS in the date and time of the tool class, which contains the date object passed in, formatted into the desired format, * or in the string format of the time, the second string date corresponding format can be
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.