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

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:43pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

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


member is offline

Avatar




PM


Posts: 157
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: 803
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 »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls