Time and Date Example by Mudbud Productions5th Jun 2011 17:01
|
---|
Summary This example shows the date in three formats and displays time. ALL code is free to use unless otherwise specified. Credit is appreciated but not required. Description Created By Mudbud Productions, This example shows the date in three formats and displays time. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com ///////////////////////////// //Project: Dark Basic Pro Project// //Created: Sunday, June 05, 2011/ //*****Mudbud Productions****/ //*****Calendar Example *****/ /////////////////////////// //Description.... //This example shows the date in three formats and displays time. //Set Font and size// set text font "Arial" set text size 30 //Create month DATA DATA "January", "February", "March", "April", "May", "June" DATA "July", "August", "September", "October", "November", "December" //Create months array DIM Months(12) AS STRING //Fill the months array FOR N = 1 TO 12 READ Months(N) NEXT N //Print Formats do cls PRINT "The current time is "; GetTime() PRINT "Short date: "; GetDate("short") PRINT "Medium date: "; GetDate("medium") PRINT "Long date: "; GetDate("long") //Create a way to end if spacekey() = 1 then end loop FUNCTION GetDate(format AS STRING) REM Initialize variables MyDate AS STRING Year AS STRING Month AS INTEGER Day AS INTEGER REM Retrieve month, day, year Year = "20" + RIGHT$(GET DATE$(), 2) Month = VAL(LEFT$(GET DATE$(), 2)) Day = VAL(LEFT$(RIGHT$(GET DATE$(), 5), 2)) REM Return short date IF format = "short" MyDate = STR$(Month) + "/" + STR$(Day) MyDate = MyDate + "/" + Year ENDIF REM Return medium date IF format = "medium" MyDate = LEFT$(Months(Month), 3) + " " MyDate = MyDate + STR$(Day) + ", " + Year ENDIF REM Return long date IF format = "long" MyDate = Months(Month) + " " + STR$(Day) MyDate = MyDate + ", " + Year ENDIF ENDFUNCTION MyDate FUNCTION GetTime() REM Declare some variables MyTime AS STRING AMPM AS STRING Hour AS INTEGER REM Format the time Hour = VAL(LEFT$(GET TIME$(), 2)) IF Hour > 12 Hour = Hour - 12 AMPM = " PM" ELSE AMPM = " AM" ENDIF REM Return the time MyTime = STR$(Hour) + RIGHT$(GET TIME$(), 6) + AMPM ENDFUNCTION MyTime |