Pada postingan ini saya akan memberikan sedikit contoh fungsi Action Script untuk menambahkan nilai tanggal pada bagian tertentu, baik itu tahun,bulan,tanggal,jam,menit bahkan detik.
contoh :
2010/10/01 + 3 hari = 2010/10/04
2010/10/01 + 3 bulan = 2011/01/01
2010/10/01 + 3 tahun = 2014/01/01
berikut source code nya :
contoh untuk menambahkan 3 bulan dari tanggal sistem.
contoh :
2010/10/01 + 3 hari = 2010/10/04
2010/10/01 + 3 bulan = 2011/01/01
2010/10/01 + 3 tahun = 2014/01/01
berikut source code nya :
/**
* Adds the specified number of "date parts" to a date, e.g. 6 days
* @param datepart The part of the date that will be added
* @param number The total number of "dateParts" to add to the date
* @param date The date on which to add
* @return The new date
*/
public static function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date {
if (date == null) {
/* Default to current date. */
date = new Date();
}
var returnDate:Date = new Date(date.time);;
switch (datepart.toLowerCase()) {
case "fullyear":
case "month":
case "date":
case "hours":
case "minutes":
case "seconds":
case "milliseconds":
returnDate[datepart] += number;
break;
default:
/* Unknown date part, do nothing. */
break;
}
return returnDate;
}
cara pemanggilanya :contoh untuk menambahkan 3 bulan dari tanggal sistem.
ASClass.dateAdd("month",3,new Date())