jsp時間獲取及格式化

2021-07-22 14:08:43 字數 1802 閱讀 1646

記錄,供自己參考

方法一:原生js使用date函式

//獲取系統時間

var now = new date();

var year = now.getfullyear(); //年

var month = now.getmonth() + 1; //月

var day = now.getdate(); //日

var stop_start_time = year + "-"; //封停開始時間

if(month < 10)

stop_start_time += "0";

stop_start_time += month + "-";

if(day < 10)

stop_start_time += "0";

stop_start_time += day + " ";

//開始時間

$('#stop_start_time').val(stop_start_time);

function getnowformatdate() 

if (strdate >= 0 && strdate <= 9)

var currentdate = date.getfullyear() + seperator1 + month + seperator1 + strdate

+ " " + date.gethours() + seperator2 + date.getminutes()

+ seperator2 + date.getseconds();

return currentdate;

}

方法三:

// 對date的擴充套件,將 date 轉化為指定格式的string

// 月(m)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符,

// 年(y)可以用 1-4 個佔位符,毫秒(s)只能用 1 個佔位符(是 1-3 位的數字)

// 例子:

// (new date()).format("yyyy-mm-dd hh:mm:ss.s") ==> 2006-07-02 08:09:04.423

// (new date()).format("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18

date.prototype.format = function (fmt) ;

if (/(y+)/.test(fmt)) fmt = fmt.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length));

for (var k in o)

if (new regexp("(" + k + ")").test(fmt)) fmt = fmt.replace(regexp.$1, (regexp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));

return fmt;

}呼叫:

var time1 = new date().format("yyyy-mm-dd");

var time2 = new date().format("yyyy-mm-dd hh:mm:ss");

Oracle獲取系統時間及格式化

oracle 獲取當前日期及日期格式 獲取系統日期 sysdate 格式化日期 to char sysdate yy mm dd hh24 mi ss 或 to date sysdate yy mm dd hh24 mi ss 格式化數字 to number 注 to char 把日期或數字轉換為字...

Oracle獲取系統時間及格式化

oracle獲取系統時間及格式化 獲取系統日期 sysdate 格式化日期 to char sysdate yy mm dd hh24 mi ss 或 to date sysdate yy mm dd hh24 mi ss 格式化數字 to number 注 to char 把日期或數字轉換為字串 ...

Lua獲取系統時間和時間格式化方法及格式化引數

一 系統當前時間對應的時間戳 複製 如下 local ntime os.time print ntime 二 格式化時間顯示,參考下表 常用於設定header等 複製 如下 ngx.header last modified os.date a,d b y x gmt ngx.header conte...