Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Displaying system time (not timecode)

Enthusiast ,
Apr 25, 2011 Apr 25, 2011

For the life of me, I can't find any Expressions that deal with displaying the current system time using the source text property.

What's a good way to get "04:53 PM"? (assuming the time is really 4:53PM)

Alternatively, using Dan's universal counting clock, he uses a variable named "clockStart =". What would I use to return the current system time?

TOPICS
Expressions
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 26, 2011 Apr 26, 2011

Yes, that's correct.

Dan

Translate
Community Expert ,
Apr 25, 2011 Apr 25, 2011

I haven't tested this thoroughly, but it should get you close:

D = new Date(Date(0));
h = D.getHours();
m = D.getMinutes();
suffix = h >= 12 ? "PM" : "AM";
if (h > 12) h -= 12;
h = "" + h;
if (h.length < 2) h = "0" + h;
m = "" + m;
if (m.length < 2) m = "0" + m;

h + ":" + m +" " + suffix

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 25, 2011 Apr 25, 2011

Thanks Dan! Looks like it works perfectly! (as usual)

So I could use D.getHours, D.getMinutes, and (I'm assuming) D.getSeconds to build a running military clock with seconds?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 25, 2011 Apr 25, 2011

Sure:

D = new Date(Date(0));
h = D.getHours();
m = D.getMinutes();
s = D.getSeconds();
h = "" + h;
if (h.length < 2) h = "0" + h;
m = "" + m;
if (m.length < 2) m = "0" + m;
s = "" + s;
if (s.length < 2) s = "0" + s;

h + ":" + m + ":" + s

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 26, 2011 Apr 26, 2011

so h = "" + h turns a number value into a string?  And h.length is the string length? D = new Date(Date(0)) captures the entire clock + date state?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 26, 2011 Apr 26, 2011
LATEST

Yes, that's correct.

Dan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines