In javascript, how can I get three different substrings for date, month, and year from the following line: "12/15/2009"?
If you want to do more complex date manipulation, you can also convert the string to a JavaScript Date object as follows:
var date = new Date("12/15/2009"); alert(date.getFullYear()); alert(date.getMonth() + 1); alert(date.getDate()); var newYear = new Date("1/1/2010"); alert((new Date(newYear - date)).getDate() + " days till the new year");
var date = "12/15/2009"; var parts = date.split("/"); alert(parts[0]); // 12 alert(parts[1]); // 15 alert(parts[2]); // 2009
.split(), .
var strDate = "12/15/2009"; var arrDate = strDate.split('/'); var month = arrDate[0]; var day = arrDate[1]; var year = arrDate[2];
"12", "15" "2009"? yes then 3 .
"12/15/2009".split("/")
:
var dateString = "12/15/2009"; var dateParts = dateString.split("/"); var month = dateParts[0]; var day = dateParts[1]; var year = dateParts[2];
var splitDate = "12/15/2009".split("/"); var month = splitDate[0]; var day = splitDate[1]; var year = splitDate[2];
[yourstring].split(char splitter) (i.E. date.split( "/" )). .
split :
split
var list = "12/15/2009".split('/'); var year = list[2]; var month = list[0]; var day = list[1]; console.log(day, month, year);
15 12 2009
Source: https://habr.com/ru/post/1725690/More articles:Best Eclipse plugins for java development using spring / struts / hibernate? - javaHow to remove an item from a list in a scheme - schemeLast login date or read operation in SQL Server database? - sql-serverusing Zend_Gdata_Spreadsheets for public spreadsheets? - google-spreadsheetfinding a triplet having a given sum - algorithmInvalid Cast exception in HttpFileCollection - c #Need help with problems with Apache Rewrite - apacheHow to use static function in ActionScript 3.0? - actionscriptDownload the class file dynamically (Objective-C) - objective-cDjango date filter to output "am" or "AM" - pythonAll Articles