Jump to content

PCM - Calculating 24 hour time format


---
 Share

Recommended Posts

Hello Forum - This is my first attempt at writing more than one line of code. I am trying to create a 24 hour format to include in the file name of saved results. Was there an easier way?


// ---------------------> Start Time <------------------
display("#displayCLOSE")
timeNSecs = timeInSeconds()
decHours = timeNSecs / 3600
//---------Extract Hour from Time------------------
if round(decHours) > decHours then
hours = round(decHours) - 1
else
hours = round(decHours)
endif
//---------Extract Minute from Time------------------
mins = (decHours - hours)*60
if round(mins) > mins then
mins = round(mins) - 1
else
mins = round(mins)
endif
//---------Convert to Text Values-------------------
txtHours = text(hours)
if len(txtHours) < 2 then
txtHours = 0 + txtHours
endif
txtMins = text(mins)
if len(txtMins) < 2 then
txtMins = 0 + txtMins
endif
display("This is 24 hour time: " + txtHours + txtMins)
//------------------- END-------------------------------
Link to comment
Share on other sites

I guess 12h format ends with am/pm?

if inStr("p",time()) <> 0
	if strElement(1,":",time()).asInteger +12) == 24
		"00"+":"+strElement(2,":",time())+":"+strElement(3,":",time())
	else
		format(strElement(1,":",time()).asInteger +12))+":"+strElement(2,":",time())+":"+strElement(3,":",time())
	endif
else
	time()
endif
Can be simplified if you don't work during midnight.
Link to comment
Share on other sites

 Share

×
×
  • Create New...