Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - String type conversion date type in JS
String type conversion date type in JS
In JS, the conversion from string type to date type is 1, which is a common method, but it is cumbersome. Please refer to the following:

The construction method of Date is mainly used: Date(int year, int month, int day).

& lt script & gt

var str 1 = " 2009-8-9 ";

var arr 1 = str 1 . split("-");

var Date 1 = new Date(arr 1[0],parse int(arr 1[ 1])- 1,arr 1[2]);

var str 2 = " 2009-8-4 ";

var arr 2 = str 2 . split("-");

var date2 = new Date(arr2[0],parse int(arr 2[ 1])- 1,arr 2[2]);

alert(date 1 & gt; Date 2); real

& lt/script & gt;

2. The relatively simple method is as follows:

var str = " 2005- 12- 15 ";

Var d = new date (str.replace(/-/g, "/");

Example:

& lt script & gt

var s = " 20 10-09- 1 1 ";

var s 1 = " 20 10-09- 12 ";

Var d = new date (s.replace(/-/g, "/");

Var d 1 = new date (s1.replace (//g, "/);

var m =(d 1 . gettime()-d . gettime())/( 1000 * 60 * 60);

Alarm (m); 24

& lt/script & gt;

How to Convert Date Type to String Type

Date type is converted into string, and string is converted into date type, which is manually converted in jsp/servlet and automatically converted in struts2.

SimpleDateFormat is a concrete class that formats and parses dates in a way that is relevant to the language environment. It allows formatting (date-> Text), analysis (text->; Date) and normalization.

: Blog. /Android-5/archive/20 12/05/ 12/2533652。

You can refer to this in detail, and there are graphic tutorials, hoping to help you.

How to Convert String Type to Date Type

By default, data has toString ().

Output Greenwich mean time, such as datedate = newdate ();

string toStr = date . tostring();

The output is similar to:

Wednesday September1619: 02: 36 CST 2012

If you want to output the format yyyy-MM-dd hh:mm:ss,

Using the SimpleDataFormat class

take for example

Date Date = new Date();

string dateStr = new simple dateformat(" yyyy-MM-DD hh:MM:ss ")。 Format (date);

system . out . println(dateStr);

The output is as follows:

2009-09- 16 07:02:36 Of course, you can also delete: hh:mm:ss, and the output result will only be year-month-day.

Conversion between string type and decimal type in delphi

You can try the following methods:

TryStrToFloat(String,Float);

This function returns a Boolean value indicating whether the conversion was successful. STRING represents a variable of STRING type that needs to be converted, and FLOAT is a variable of FLOAT type that receives the converted value.

How to convert a date type into a string type in java?

By default, data lets toString () output Greenwich Mean Time.

Use the SimpleDataFormat class if you want to output yyyy-MM-dd hh:mm:ss format.

take for example

Date Date = new Date();

System.out.println (date);

string dateStr = new simple dateformat(" yyyy-MM-DD hh:MM:ss ")。 Format (date);

system . out . println(dateStr);

The output is as follows:

Wednesday, 6 September 2009

2009-09- 16 07:02:36

How to convert a string type into a java.sql.Date type in java?

string str = " 1989- 1 1-23 12:25:20 ";

Java . SQL . date date = Java . SQL . date . value of(str);

This can be converted, but only if the date format of str is the same as that in the database, that is, MySql, and others such as Oracle are different from this.

Convert double type to String type in java?

The provider in the String class can convert almost all basic types into String types, so you can call String.valueOf(222.222). This method returns a string corresponding to a double.

The sample code is as follows

package . lk . simple developer . test; public class Test { public static void main(String[]args){ double d = 12.25; string str = string . value of(d); system . out . println(str); }}

How to convert a string type into a date type in java?

In Java, the common time conversion is usually from string type to date type, and vice versa. During the conversion process, we can customize the time format as follows:

If you want to define the time type as yyyy-MM-dd, you can first define the format: simple date format = new simple date format ("yyyy-mm-DD");

This sentence is necessary and indispensable. Then we convert s from String type to time type by calling the parse(String s) method of dateFormat. If we call the format(Date d) method of dateFormat, we can convert d from date type to string type.