Date objects Convert--tostring, totimestring, todatestring, toUTCString, toLocaleString (), tolocaletimestring (), toLocaleDateString ()

Source: Internet
Author: User

JavaScript toString () method

JavaScript Date Object Reference Manual

definition and Usage:the toString () method converts a Date object to a string and returns the result.

Syntax:dateobject.tostring ()

return Value:A string representation of dateobject, expressed using local time.

Example

In this example, we will convert today's date to a string:

<script type= "Text/javascript" >    varnew  Date ()    document.write (d.tostring ()) </script>

Output:Tue Apr 10:05:35 gmt+0800 (China Standard Time)

JavaScript totimestring () method

definition and Usage:the totimestring () method converts the time portion of a Date object to a string and returns the result.

Syntax:dateobject.totimestring ()

return Value:The string representation of the time portion of the dateobject, as determined by the implementation, using local time representation.

Example

In this example, we will convert today's date to a string based on local time:

<script type= "Text/javascript" >    varnew  Date ()    document.write (d.totimestring ( ))</script>

Output:10:05:58 gmt+0800 (China Standard Time)

JavaScript todatestring () method

definition and Usage:the todatestring () method converts the date part of a DateTime object to a string and returns the result.

Syntax:dateobject.todatestring ()

return Value:The string representation of the date part of Dateobject, as determined by the implementation, using local time representation.

Example

In this example, we will convert today's date to a string based on local time:

<script type= "Text/javascript" >    varnew  Date ()    document.write (d.todatestring ( ))</script>

Output:Tue Apr

JavaScript toutcstring () method

definition and Usage:the toUTCString () method converts a Date object to a string based on Universal Time (UTC) and returns the result.

Syntax:dateobject.toutcstring ()

return Value:A string representation of dateobject, expressed in world time.

Example 1

In the following example, we will use toUTCString () to convert today's date to a (based on UTC) string:

<script type= "Text/javascript" >    varnew  Date ()    document.write ( D.toutcstring ())</script>

Output:Tue, APR 02:06:45 GMT

Example 2

In the following example, we will convert the specific date to a string (based on UTC):

<script type= "Text/javascript" >    varnew Date ("July, 1983 01:15:00")    document.write (Born.toutcstring ())</script>

Output:Wed, Jul 1983 17:15:00 GMT

JavaScript tolocalestring () method

definition and Usage:the toLocaleString () method converts a Date object to a string based on local time and returns the result.

Syntax:dateobject.tolocalestring ()

return Value:A string representation of dateobject, expressed as a local time zone, and formatted according to local rules.

Example 1

In this example, we will convert today's date to a string based on local time:

<script type= "Text/javascript" >    varnew  Date ()    document.write ( D.tolocalestring ())</script>

Output:2015/4/28 morning 10:07:15

Example 2

In this case, we will convert the specific date to a string based on local time:

<script type= "Text/javascript" >    varnew Date ("July, 1983 01:15:00")    document.write (Born.tolocalestring ())</script>

Output:1983/7/21 morning 1:15:00

JavaScript tolocaletimestring () method

definition and Usage:the tolocaletimestring () method converts the time portion of a Date object to a string based on local time and returns the result.

Syntax:dateobject.tolocaletimestring ()

return Value:A string representation of the time portion of the dateobject, expressed as a local time zone, and formatted according to local rules.

Example

In this example, we will convert today's date to a string based on local time:

<script type= "Text/javascript" >    varnew  Date ()    document.write ( D.tolocaletimestring ())</script>

Output: morning 10:07:35

JavaScript tolocaledatestring () method

definition and Usage:the tolocaledatestring () method converts the date part of a DateTime object to a string based on local time and returns the result.

Syntax:dateobject.tolocaledatestring ()

return Value:A string representation of the date part of Dateobject, expressed as a local time zone, and formatted according to local rules.

Example

In this example, we will convert today's date to a string based on local time:

<script type= "Text/javascript" >    varnew  Date ()    document.write ( D.tolocaledatestring ())</script>

Output:2015/4/28

Date objects Convert--tostring, totimestring, todatestring, toUTCString, toLocaleString (), tolocaletimestring (), toLocaleDateString ()

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.