BBC BASIC
« TIME$-- convert the current time to 12hr »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 4:22pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: TIME$-- convert the current time to 12hr  (Read 45 times)
michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 141
xx TIME$-- convert the current time to 12hr
« Thread started on: Nov 25th, 2017, 03:36am »

I am sure someone will come up with a better example, but for now if you want to extract the current time and convert the 24 hour clock to 12 hour clock then I think I did it correctly.. If not let me know.. Thanks
Code:
      MODE 8
      REPEAT
        t$= RIGHT$(TIME$,8)
        h$= LEFT$(t$,2)
        m$= MID$(t$,4,2)
        s$= RIGHT$(t$,2)
        LET std%=VAL(h$)
        CASE std% OF
          WHEN 13 :h$="01"
          WHEN 14 :h$="02"
          WHEN 15:h$="03"
          WHEN 16:h$="04"
          WHEN 17:h$="05"
          WHEN 18:h$="06"
          WHEN 19:h$="07"
          WHEN 20:h$="08"
          WHEN 21:h$="09"
          WHEN 22:h$="10"
          WHEN 23:h$="11"
          WHEN 00:h$="12"
        ENDCASE
  
        PRINT h$+":"+m$+":"+s$
        WAIT 10
        CLS
      UNTIL FALSE
      END
 
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: TIME$-- convert the current time to 12hr
« Reply #1 on: Nov 25th, 2017, 09:27am »

on Nov 25th, 2017, 03:36am, michael wrote:
I think I did it correctly.. If not let me know

There's nothing 'wrong' with your code, but conversion of the 24-hour clock to the 12-hour clock is just arithmetic; you can easily do it in a single BASIC statement:

Code:
      REPEAT
        t$ = RIGHT$(TIME$,8)
  
        REM Convert 24-hour clock to 12-hour clock:
        LEFT$(t$,2) = RIGHT$("0"+STR$((VAL(t$)+11)MOD12+1),2)
  
        CLS
        PRINT t$
        WAIT 10
      UNTIL FALSE 

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls