روش های تاریخ و زمان

روش های تاریخ و زمان

روش های تاریخ و زمان
از روش‌های تاریخ و زمان برای بازیابی تاریخ و زمان فعلی و همچنین اطلاعات مربوط به زمان‌های محاسبه استفاده می‌شود.

 
Name
Syntax
Description
currentDate
String currentDate()
Returns the current date as a string (formatted according to the server’s defaults) for the current date.
currentTime
String currentTime()
Returns the current time as a string (not including date, and formatted according to the server defaults).
formattedTime
String formattedTime(long timeInMs, String format)
Returns a formatted time using the given format. The format can either be a time unit or a text describing a longer format. Supported formats are:
’hr:min:sec’ which returns the time in hours, minutes and seconds in the form X hr Y min Z sec.
’h:min:s’ which returns the time in hours, minutes and seconds in the form X h Y min Z s.
’detailed’ which returns the time in seconds and also includes more readable units for longer times.
sleep
sleep(long timeInMs)
Sleep for the specified number of milliseconds.
timeStamp
long timeStamp()
Current time in milliseconds since midnight, January 1, 1970 UTC.
getExpectedComputationTime
model.setExpectedComputationTime(String format)
Returns a string describing the approximate computation time of the application. The string can be altered by the method setExpectedComputationTime.
setLastComputationTime
model.setLastComputationTime(long time)
Set the last computation time, overwriting the automatically generated time.
You can use the timeStamp method to record time differences and set the measured time in ms (a long integer).
getLastComputationTime
String model.getLastComputationTime (String format)
Returns the last computation time in the given format. The format can either be a time unit or text describing a longer format. Currently supported formats are:
hr:min:sec Returns the time in hours, minutes, and seconds in the format X h Y min Z sec.
h:min:s Returns the time in hours, minutes, and seconds in the format X h Y min Z s.
detailed Returns the time in seconds and also includes more readable units for longer times. This format is localized and the output is translated to the current language setting.
For example, you can retrieve the time in ms by using getLastComputationTime(ms).

کد مثال
کد زیر زمان محاسبات داخلی را که در گره های اطلاعاتی درخت مدل موجود است، لغو می کند.
long t0 = timeStamp(); // مقداردهی اولیه رکورد زمان محاسبات
// کد و محاسبات
model.setLastComputationTime(timeStamp()-t0); // ثبت زمان محاسبه
اگر می توان تخمین تقریبی از زمان محاسبات را بر اساس ورودی های داده شده یک برنامه ارائه داد، می توانید زمان محاسبه مورد انتظار را به روز کنید و آن را در پشته کارت اطلاعات یا یک شی متن نمایش دهید. فرض کنید یک ورودی عدد صحیح به نام اشیا وجود دارد که تعداد اشیاء در یک آرایه هندسی را کنترل می کند و محاسبه تقریباً با این عدد به صورت خطی افزایش می یابد. کد زیر زمان محاسبات مورد انتظار را بر این اساس تنظیم می کند.
// تعداد دقیقه زمان محاسبه برای هر شی
int minutes = اشیاء*2.1;
model.setExpectedComputationTime(“About” + دقیقه + “دقیقه”);
خواب
کد زیر برنامه را به مدت 1000 میلی ثانیه بیکار می کند.
تاخیر طولانی = 1000;
خواب (تاخیر)؛
از این تکنیک می توان برای نمایش گرافیک به صورت متوالی استفاده کرد.
برای اطلاعات بیشتر در مورد گره‌های اطلاعات و کارت‌های اطلاعات و همچنین روش خواب، به کتاب مقدمه‌ای بر برنامه‌ساز مراجعه کنید.