Js獲取當前日期時間及格式化操作

2022-08-01 11:12:10 字數 1183 閱讀 1300

var mydate = new date();

mydate.getyear();        //獲取當前年份(2位)

mydate.getfullyear();    //獲取完整的年份(4位,1970-????)

mydate.getmonth();       //獲取當前月份(0-11,0代表1月)

mydate.getdate();        //獲取當前日(1-31)

mydate.getday();         //獲取當前星期x(0-6,0代表星期天)

mydate.gettime();        //獲取當前時間(從1970.1.1開始的毫秒數)

mydate.gethours();       //獲取當前小時數(0-23)

mydate.getminutes();     //獲取當前分鐘數(0-59)

mydate.getseconds();     //獲取當前秒數(0-59)

mydate.getmilliseconds();    //獲取當前毫秒數(0-999)

mydate.tolocaledatestring();     //獲取當前日期

var mytime=mydate.tolocaletimestring();     //獲取當前時間

mydate.tolocalestring( );        //獲取日期與時間

日期時間指令碼庫方法列表

date.prototype.isleapyear 判斷閏年

date.prototype.format 日期格式化

date.prototype.dateadd 日期計算

date.prototype.datediff 比較日期差

date.prototype.tostring 日期轉字串

date.prototype.toarray 日期分割為陣列

date.prototype.datepart 取日期的部分資訊

date.prototype.maxdayofdate 取日期所在月的最大天數

date.prototype.weeknumofyear 判斷日期所在年的第幾周

stringtodate 字串轉日期型

isvaliddate 驗證日期有效性

checkdatetime 完整日期時間檢查

daysbetween 日期天數差

PHP獲取當前日期和時間及格式化方法引數

使用函式 date 實現 顯示的格式 年 月 日 小時 分鐘 秒 相關時間引數 a am 或是 pm a am 或是 pm d 幾日,二位數字,若不足二位則前面補零 如 01 至 31 d 星期幾,三個英文本母 如 fri f 月份,英文全名 如 january h 12 小時制的小時 如 01 至...

JS日期,JS獲取當前日期時間,js日期格式化

var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 注意別忘了 1 mydate.getdate 獲取當前日 1 31 my...

Django 獲取當前時間 以及格式化日期的方法

timezone.now 返回的是當前時間,utc。格式化時間字串的方法 strftime y m d h m s 注意,除了 m 和 d 是小寫字母外,其他均為大寫。本地時間的轉換 timezone.localtime timezone.now 其實,還有乙個獲取本地時間的直接方法 timezon...