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

 BBC BASIC Programming BBC BASIC Language (Moderator: Richard Russell)  TIME\$-- convert the current time to 12hr « Previous Topic | Next Topic »
 Pages: 1
 Author Topic: TIME\$-- convert the current time to 12hr  (Read 122 times)
michael
Full Member

member is offline

Posts: 157
 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
```
 Logged

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

member is offline

Posts: 803
 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.
 Logged

 Pages: 1
 Forum Jump ------------------ => General ------------------ - General Board - Announcements - Support and Promote ------------------ => Development ------------------ - Interpreter & Run-Time Engine - Integrated Development Environment - Linux (86) - Mac OS-X - Android - Raspberry Pi - iOS ------------------ => Programming ------------------ - BBC BASIC Language - Operating System Interface - VDU Emulation - Libraries - Assembly Language - Communication and Input/Output - Database and Files - Graphics and Games - Sound, Music and Video - User Interface « Previous Topic | Next Topic »

| |