node.js
Universal Coding Style
// getTime12.js
function getTime12()
{
// new date object for current date and time
let now = new Date();
// time as 12 hour format AM/PM
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
let ampm;
// determine AM or PM
if (hours >= 12)
{
ampm = 'PM';
}
else
{
ampm = 'AM';
}
// convert to 12 hour format
hours = hours % 12;
if (hours === 0)
{
// the hour 0 should be 12
hours = 12;
}
// pad minutes with leading zeros if needed
if (minutes < 10)
{
minutes = '0' + minutes;
}
// pad seconds with leading zeros if needed
if (seconds < 10)
{
seconds = '0' + seconds;
}
// return formatted time
return hours + ':' + minutes + ':' + seconds + ' ' + ampm;
}
if (require.main === module)
{
console.log(getTime12());
}
module.exports = getTime12;
//----//
/*
4:15:30 PM
*/
// Dedicated to God the Father
// All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
// https://github.com/ChristopherTopalian
// https://github.com/ChristopherAndrewTopalian
// https://sites.google.com/view/CollegeOfScripting
// getTime24.js
function getTime24()
{
// new date object for current date and time
let now = new Date();
// time as 12 hour format AM/PM
let hours = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
if (hours === 0)
{
// the hour 0 should be 12
hours = 12;
}
// pad minutes with leading zeros if needed
if (minutes < 10)
{
minutes = '0' + minutes;
}
// pad seconds with leading zeros if needed
if (seconds < 10)
{
seconds = '0' + seconds;
}
// return formatted time
return hours + ':' + minutes + ':' + seconds;
}
if (require.main === module)
{
console.log(getTime24());
}
module.exports = getTime24;
//----//
/*
19:10:55
*/
// Dedicated to God the Father
// All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
// https://github.com/ChristopherTopalian
// https://github.com/ChristopherAndrewTopalian
// https://sites.google.com/view/CollegeOfScripting
// Time.js
const getTime12 = require('./getTime12.js');
const getTime24 = require('./getTime24.js');
// class that uses imported functions
class Time
{
static getTime12()
{
return getTime12();
}
static getTime24()
{
return getTime24();
}
}
module.exports = Time;
//----//
// Dedicated to God the Father
// All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
// https://github.com/ChristopherTopalian
// https://github.com/ChristopherAndrewTopalian
// https://sites.google.com/view/CollegeOfScripting
// usesClassTime.js
const Time = require('./Time.js');
console.log(Time.getTime12());
console.log(Time.getTime24());
process.stdin.resume();
process.stdin.once('data', function()
{
process.exit();
});
//----//
/*
7:15:47 PM
19:15:47
*/
// Dedicated to God the Father
// All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
// https://github.com/ChristopherTopalian
// https://github.com/ChristopherAndrewTopalian
// https://sites.google.com/view/CollegeOfScripting
python
Universal Coding Style
# getTime12.py
import datetime as dt
def getTime12():
now = dt.datetime.now()
currentTime = now.strftime("%I:%M:%S %p")
return currentTime
##
if __name__ == "__main__":
print(getTime12())
input('')
####
'''
05:43:07 PM
'''
# Dedicated to God the Father
# All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
# https://github.com/ChristopherTopalian
# https://github.com/ChristopherAndrewTopalian
# https://sites.google.com/view/CollegeOfScripting
# getTime24.py
import datetime as dt
def getTime24():
now = dt.datetime.now()
currentTime = now.strftime("%H:%M:%S")
return currentTime
##
if __name__ == "__main__":
print(getTime24())
input('')
####
'''
19:30:10
'''
# Dedicated to God the Father
# All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
# https://github.com/ChristopherTopalian
# https://github.com/ChristopherAndrewTopalian
# https://sites.google.com/view/CollegeOfScripting
# Time.py
from getTime12 import getTime12
from getTime24 import getTime24
class Time:
getTime12 = getTime12
getTime24 = getTime24
##
# Dedicated to God the Father
# All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
# https://github.com/ChristopherTopalian
# https://github.com/ChristopherAndrewTopalian
# usesClassTime.py
import Time
print(Time.getTime12())
print(Time.getTime24())
input('')
####
'''
07:35:41 PM
19:35:41
'''
# Dedicated to God the Father
# All Rights Reserved Christopher Andrew Topalian Copyright 2000-2024
# https://github.com/ChristopherTopalian
# https://github.com/ChristopherAndrewTopalian
# https://sites.google.com/view/CollegeOfScripting