Class Demo.Obj Extends %RegisteredObject
{Property Name As %String;/// d ##class(Demo.Obj).Command()
ClassMethod Command()
{// 定義對象,將對象的引用給obj變量set obj = ##class(Obj).%New()// 輸出15@Demo.Objw obj,!
}}
使用$isobject判斷是否為對象
// 輸出1
w $isobject(obj)// 輸出0
w $isObject("123")
定義多個同一個對象時,會產生增加對象的內部引用計數
set obj = ##class(Obj).%New()
// 輸出16@Demo.Obj
w obj,!set obj2 = ##class(Obj).%New()
// 輸出16@Demo.Obj
w obj2,!/* 輸出如下:
obj=<OBJECT REFERENCE>[15@Demo.Obj]
+----------------- general information ---------------
| oref value: 16
| class name: Demo.Obj
| reference count: 2
+----------------- attribute values ------------------
| Name = ""
+-----------------------------------------------------
*/
zw obj2
/// This callback method is invoked by the <METHOD>%Close</METHOD> method to
/// provide notification that the current object is being closed.
///
/// <P>The return value of this method is ignored.
Method %OnClose() As %Status [ Private, ServerOnly = 1 ]
{Quit $$$OK
}
// 輸出08/07/2022
w $zdate($horolog),!
// 輸出2022-08-07
w $zd($horolog, 3),!// 輸出66328
w $zdateh("08/07/2022"),!
// 輸出66328
w $zdh("2022-08-07", 3),!
// T表示當天, 輸出66328
w $zdh("T", 5),!
$ztime(縮寫$zt):驗證時間,并將其從數字格式轉換為顯示指定的時間格式
$ztimeh(縮寫$zth):將時間格式轉換為時間格式
$zt(時間數字,格式)->時間
$zth(時間,格式) -> 數字
// 輸出14:27:02
w $ztime($p($horolog, ",", 2)),!// 輸出02:27:02PM
w $zt($p($horolog, ",", 2), 3),!// 輸出52022
w $ztimeh("14:27:02"),!
// 輸出52022
w $zth("02:27:02PM", 3),!
$zdatetime(縮寫$zdt):驗證日期和時間,將數字轉換為日期和時間
$zdt(日期和時間數字,格式)->日期和時間
$zdth(日期和時間,格式) ->日期和時間數字
// 輸出08/07/2022 14:33:36
w $zdatetime($h),!
// 輸出2022-08-07 14:33:36
w $zdt($h, 3),!// 輸出66328,52416
w $zdatetimeh("08/07/2022 14:33:36"),!
// 輸出66328,52416
w $zdatetimeh("2022-08-07 14:33:36", 3),!
// 輸出66328,0
w $zdth("T", 5),!
$zhorolog(縮寫$zh):返回啟動Cache庫以來,經過的秒數。
// 輸出101268.602726
w $zhorolog,!// 輸出28.13016890888888889
w $zhorolog/3600,!
????????$zhorolog還可以用于計算程序運行的時間:
set t1 = $zh//等待2秒鐘
hang 2set t2 = $zh// 輸出2.000593
w t2 - t1