Date and Time Source Codes
Laman ini dikhususkan untuk meletakan semua Source Code dalam beberapa Bahasa Pemrograman untuk Sistem Penanggalan Tanggal dan Waktu. Untuk Fitur ini hanya tersedia untuk Penanggalan Umum (Masehi/Gregorian) saja dan tidak tersedia untuk Penanggalan Hijriah/Islam, karena Algoritma-nya terlalu sulit dan rumit untuk Penanggalan Hijriah. Laman ini juga merupakan bagian dari CALENDAR SYSTEM.
Untuk melihat Kode Program Sistem Penanggalan dalam berbagai Bahasa Pemrograman, silakan lihat di sini (Github.com).
1. Sumber Referensi
Dibawah inilah Link untuk Referensi Tanggal dan Waktu dalam beberapa Bahasa Pemrograman :
- https://www.w3schools.com/python/python_datetime.asp (Python)
- https://www.tutorialspoint.com/java/java_date_time.htm (Java)
- https://jenkov.com/tutorials/java-internationalization/simpledateformat.html (Java)
- https://www.tutorialspoint.com/java/util/calendar_getinstance_locale.htm (Java)
- https://www.tabnine.com/code/java/methods/java.util.Calendar/get (Java)
- https://www.tutorialspoint.com/Date-Formatting-Using-SimpleDateFormat (Java)
- https://www.c-sharpcorner.com/article/datetime-in-c-sharp (C#)
- https://www.c-sharpcorner.com/blogs/date-and-time-format-in-c-sharp-programming1 (C#)
- https://www.tutorialsteacher.com/csharp/csharp-datetime (C#)
- https://www.tutorialspoint.com/cplusplus/cpp_date_time.htm (C++)
- https://www.softwaretestinghelp.com/date-and-time-in-cpp (C++)
- https://www.tutorialcup.com/cplusplus/date-time.htm (C++)
- https://codescracker.com/cpp/cpp-date-time.htm (C++)
- https://zetcode.com/articles/cdatetime (C)
- https://codescracker.com/c/program/c-program-print-date.htm (C)
- https://www.techiedelight.com/print-current-date-and-time-in-c (C)
- https://www.w3schools.com/jsref/jsref_obj_date.asp (Javascript)
- https://www.programiz.com/javascript/date-time (Javascript)
- https://code.tutsplus.com/tutorials/working-with-date-and-time-in-php--cms-31768 (PHP)
- https://www.w3schools.com/php/func_date_date.asp (PHP)
- https://www.arclab.com/en/kb/htmlcss/display-date-time-javascript-php-ssi.html (Javascript & PHP)
- https://www.w3schools.blog/date-object-typescript (Typescript)
- https://www.javatpoint.com/typescript-date-object (Typescript)
- https://www.tutorialspoint.com/ruby/ruby_date_time.htm (Ruby)
- https://www.digitalocean.com/community/tutorials/how-to-use-dates-and-times-in-go (Golang)
- https://zetcode.com/golang/datetime (Golang)
- https://r4ds.had.co.nz/dates-and-times.html (R)
- https://bookdown.org/rdpeng/rprogdatascience/dates-and-times.html (R)
- https://www.stat.berkeley.edu/~s133/dates.html (R)
- https://api.dart.dev/stable/3.2.1/dart-core/DateTime-class.html (Dart)
- https://medium.com/flutter-community/working-with-dates-in-dart-e81c70911811 (Dart)
- https://dart-tutorial.com/useful-information/date-time-in-dart (Dart)
- https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.js/-date (Kotlin)
- https://www.baeldung.com/kotlin/current-date-time (Kotlin)
2. Source Code
1. Python (Text-Based)
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di Python :
import datetimex = datetime.datetime.now()thn = x.yearbln = x.monthbul = x.strftime("%B")tgl = x.strftime("%d")har = x.strftime("%w")hari = x.strftime("%A")harke = x.strftime("%j")waktu = x.strftime("%X")jam = x.strftime("%H")mnt = x.strftime("%M")dtk = x.strftime("%S")if hari == "Sunday":har = 7print("Tahun : "+str(thn))print("Bulan : "+str(bln)+" ("+str(bul)+")")print("Tanggal : "+str(tgl))print("Hari : "+str(har)+" ("+str(hari)+")")print("Hari ke (dalam Setahun) : "+str(harke))print("Jam : "+str(jam))print("Menit : "+str(mnt))print("Detik : "+str(dtk))print()print(str(hari)+", "+str(tgl)+" "+str(bul)+" "+str(thn))print("Day-"+str(harke))print(str(waktu))
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di Python (Dengan Persentase Tahun) :
import datetimex = datetime.datetime.now()thn = x.yearbln = x.monthbul = x.strftime("%B")tgl = x.strftime("%d")har = x.strftime("%w")hari = x.strftime("%A")harke = x.strftime("%j")waktu = x.strftime("%X")jam = x.strftime("%H")mnt = x.strftime("%M")dtk = x.strftime("%S")if thn % 400 == 0:leap=366elif thn % 100 == 0:leap=365elif thn % 4 == 0:leap=366else:leap=365persen = 100/float(leap)*(float(harke)-1+(float(jam)/24)+(float(mnt)/1440)+(float(dtk)/86400))harmun = 1+leap-int(harke)permun = 100-persenif hari == "Sunday":har = 7print("Tahun : "+str(thn))print("Bulan : "+str(bln)+" ("+str(bul)+")")print("Tanggal : "+str(tgl))print("Hari : "+str(har)+" ("+str(hari)+")")print("Hari ke (dalam Setahun) : "+str(harke))print("Sisa Hari (Tahun depan) : "+str(harmun))print("Persentase dalam Setahun : "+str(round(persen, 6))+"%")print("Persentase Hitung Mundur : "+str(round(permun, 6))+"%")print("Jam : "+str(jam))print("Menit : "+str(mnt))print("Detik : "+str(dtk))print()print(str(hari)+", "+str(tgl)+" "+str(bul)+" "+str(thn))print("Day-"+str(harke)+" ("+str(round(persen, 4))+"%)")print(str(waktu))
2. Python (GUI - Tkinter)
a. Tanpa Persentase Tahun
import tkinter as tkimport datetimedef update_time():current_time = datetime.datetime.now()year = str(current_time.year)month = str(current_time.month)month_name = current_time.strftime("%B")day = current_time.strftime("%w")day_name = current_time.strftime("%A")day_of_year = current_time.strftime("%j")hour = current_time.strftime("%H")minute = current_time.strftime("%M")second = current_time.strftime("%S")if day_name == "Sunday":day = "7"year_label.config(text="Tahun : " + year)month_label.config(text="Bulan : " + month + " (" + month_name + ")")date_label.config(text="Tanggal : " + day)day_label.config(text="Hari : " + day_name)day_of_year_label.config(text="Hari ke (dalam Setahun) : " + day_of_year)hour_label.config(text="Jam : " + hour)minute_label.config(text="Menit : " + minute)second_label.config(text="Detik : " + second)root.after(1000, update_time)root = tk.Tk()root.title("Penanggalan")root.geometry("320x200")root.resizable(False, False)frame = tk.Frame(root, padx=20)frame.pack(fill=tk.BOTH)year_label = tk.Label(frame, text="Tahun: ")year_label.pack(anchor=tk.W)month_label = tk.Label(frame, text="Bulan: ")month_label.pack(anchor=tk.W)date_label = tk.Label(frame, text="Tanggal: ")date_label.pack(anchor=tk.W)day_label = tk.Label(frame, text="Hari: ")day_label.pack(anchor=tk.W)day_of_year_label = tk.Label(frame, text="Hari ke (dalam Setahun): ")day_of_year_label.pack(anchor=tk.W)hour_label = tk.Label(frame, text="Jam: ")hour_label.pack(anchor=tk.W)minute_label = tk.Label(frame, text="Menit: ")minute_label.pack(anchor=tk.W)second_label = tk.Label(frame, text="Detik: ")second_label.pack(anchor=tk.W)update_time()root.mainloop()
Hasil Output :
b. Dengan Persentase Tahun
import tkinter as tkfrom datetime import datetimeclass DateInfoApp:def __init__(self, root):self.root = rootself.root.title('Penanggalan')self.root.geometry('350x280') # Set window sizeself.result_label = tk.Label(root, justify='left')self.time_label = tk.Label(root, justify='left')self.result_label.pack(pady=10, padx=10, anchor='w') # Align leftself.time_label.pack(padx=10, anchor='w') # Align leftself.update_time()def update_time(self):current_datetime = datetime.now()thn = current_datetime.yearbln = current_datetime.monthbul = current_datetime.strftime('%B')tgl = current_datetime.dayhar = current_datetime.strftime('%w')hari = current_datetime.strftime('%A')harke = current_datetime.strftime('%j')waktu = current_datetime.strftime('%X')jam = current_datetime.strftime('%H')mnt = current_datetime.strftime('%M')dtk = current_datetime.strftime('%S')leap = 366 if (thn % 400 == 0) or (thn % 4 == 0 and thn % 100 != 0) else 365persen = 100 / leap * (float(harke) - 1 + (float(jam) / 24) + (float(mnt) / 1440) + (float(dtk) / 86400))harmun = 1 + leap - int(harke)permun = 100 - persenif hari == "Sunday":har = 7result_text = (f"Tahun : {thn}\n"f"Bulan : {bln} ({bul})\n"f"Tanggal : {tgl}\n"f"Hari : {har} ({hari})\n"f"Hari ke (dalam Setahun) : {harke}\n"f"Sisa Hari (Tahun depan) : {harmun}\n"f"Persentase dalam Setahun : {round(persen, 6)}%\n"f"Persentase Hitung Mundur : {round(permun, 6)}%\n"f"Jam : {jam}\n"f"Menit : {mnt}\n"f"Detik : {dtk}")time_text = f"{hari}, {tgl} {bul} {thn}\nDay-{harke} ({round(persen, 4)}%)\n{waktu}"self.result_label.config(text=result_text)self.time_label.config(text=time_text)self.root.after(1000, self.update_time)if __name__ == '__main__':root = tk.Tk()app = DateInfoApp(root)root.mainloop()
Hasil Output :
3. Python (GUI - PyQt5)
a. Tanpa Persentase Tahun
import sysfrom PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidgetfrom PyQt5.QtCore import QTimer, QTime, Qt, QDateclass Penanggalan(QMainWindow):def __init__(self):super().__init__()self.setWindowTitle("Penanggalan")self.setGeometry(20, 50, 320, 200)self.setFixedSize(320, 200) # To make it non-resizablecentral_widget = QWidget()self.setCentralWidget(central_widget)layout = QVBoxLayout(central_widget)self.labels = []self.add_label("Tahun : ")self.add_label("Bulan : ")self.add_label("Tanggal : ")self.add_label("Hari : ")self.add_label("Hari ke (dalam Setahun) : ")self.add_label("Jam : ")self.add_label("Menit : ")self.add_label("Detik : ")self.update_labels()self.timer = QTimer(self)self.timer.timeout.connect(self.update_labels)self.timer.start(1000)def add_label(self, text):label = QLabel(text)self.labels.append(label)layout = self.centralWidget().layout()layout.addWidget(label, alignment=Qt.AlignLeft)def update_labels(self):current_time = QTime.currentTime()current_date = QDate.currentDate()year = str(current_date.year())month = str(current_date.month())month_name = current_date.toString("MMMM")day = str(current_date.day())day_name = current_date.toString("dddd")day_of_year = str(current_date.dayOfYear())hour = str(current_time.hour())minute = str(current_time.minute())second = str(current_time.second())self.labels[0].setText("Tahun : " + year)self.labels[1].setText("Bulan : " + month + " (" + month_name + ")")self.labels[2].setText("Tanggal : " + day)self.labels[3].setText("Hari : " + day_name)self.labels[4].setText("Hari ke (dalam Setahun) : " + day_of_year)self.labels[5].setText("Jam : " + hour)self.labels[6].setText("Menit : " + minute)self.labels[7].setText("Detik : " + second)if __name__ == "__main__":app = QApplication(sys.argv)penanggalan = Penanggalan()penanggalan.show()sys.exit(app.exec_())
Hasil Output :
b. Dengan Persentase Tahun
import sysfrom PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QWidgetfrom PyQt5.QtCore import QTimer, QDateTimeclass DateInfoApp(QMainWindow):def __init__(self):super().__init__()self.init_ui()def init_ui(self):self.setWindowTitle("Penanggalan")self.setGeometry(100, 100, 400, 200)self.result_label = QLabel(self)self.time_label = QLabel(self)layout = QVBoxLayout()layout.addWidget(self.result_label)layout.addWidget(self.time_label)container = QWidget()container.setLayout(layout)self.setCentralWidget(container)self.timer = QTimer(self)self.timer.timeout.connect(self.update_time)self.timer.start(1000) # Update every 1 secondself.update_time()def update_time(self):current_datetime = QDateTime.currentDateTime()thn = current_datetime.date().year()bln = current_datetime.date().month()bul = current_datetime.toString("MMMM")tgl = current_datetime.date().day()har = current_datetime.date().dayOfWeek()hari = current_datetime.toString("dddd")harke = current_datetime.date().dayOfYear()waktu = current_datetime.time().toString("hh:mm:ss")jam = current_datetime.time().hour()mnt = current_datetime.time().minute()dtk = current_datetime.time().second()leap = 366 if (thn % 400 == 0) or (thn % 4 == 0 and thn % 100 != 0) else 365persen = 100 / leap * (harke - 1 + (jam / 24) + (mnt / 1440) + (dtk / 86400))harmun = 1 + leap - harkepermun = 100 - persenif hari == "Sunday":har = 7result_text = (f"Tahun : {thn}\n"f"Bulan : {bln} ({bul})\n"f"Tanggal : {tgl}\n"f"Hari : {har} ({hari})\n"f"Hari ke (dalam Setahun) : {harke}\n"f"Sisa Hari (Tahun depan) : {harmun}\n"f"Persentase dalam Setahun : {round(persen, 6)}%\n"f"Persentase Hitung Mundur : {round(permun, 6)}%\n"f"Jam : {jam}\n"f"Menit : {mnt}\n"f"Detik : {dtk}")time_text = (f"{hari}, {tgl} {bul} {thn}\nDay-{harke} ({round(persen, 4)}%)\n{waktu}")self.result_label.setText(result_text)self.time_label.setText(time_text)if __name__ == "__main__":app = QApplication(sys.argv)window = DateInfoApp()window.show()sys.exit(app.exec_())
Hasil Output :
4. Ruby
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di Ruby :
dt = Time.newthn = dt.yearbln = dt.monthbul = dt.strftime("%B")tgl = dt.dayhar = dt.wdayhari = dt.strftime("%A")harke = dt.ydaywaktu = dt.strftime("%H:%M:%S")jam = dt.hourmnt = dt.mindtk = dt.secif hari == "Sunday"har = 7endputs "Tahun : #{thn}"puts "Bulan : #{bln} (#{bul})"puts "Tanggal : #{tgl}"puts "Hari : #{har} (#{hari})"puts "Hari ke (dalam Setahun) : #{harke}"puts "Jam : #{jam}"puts "Menit : #{mnt}"puts "Detik : #{dtk}"putsputs "#{hari}, #{tgl} #{bul} #{thn}"puts "Day-#{harke}"puts waktu
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di Ruby (Dengan Persentase Tahun) :
dt = Time.newthn = dt.yearbln = dt.monthbul = dt.strftime("%B")tgl = dt.dayhar = dt.wdayhari = dt.strftime("%A")harke = dt.ydaywaktu = dt.strftime("%H:%M:%S")jam = dt.hourmnt = dt.mindtk = dt.secif thn % 400 == 0leap=366elsif thn % 100 == 0leap=365elsif thn % 4 == 0leap=366elseleap=365enddateCal = (harke-1)+(jam.to_f/24)+(mnt.to_f/1440)+(dtk.to_f/86400)persen = 100*dateCal/leapharmun = 1+leap-harkepermun = 100-persenif hari == "Sunday"har = 7endputs "Tahun : #{thn}"puts "Bulan : #{bln} (#{bul})"puts "Tanggal : #{tgl}"puts "Hari : #{har} (#{hari})"puts "Hari ke (dalam Setahun) : #{harke}"puts "Sisa Hari (Tahun depan) : #{harmun}"puts "Persentase dalam Setahun : #{persen.round(6)}%"puts "Persentase Hitung Mundur : #{permun.round(6)}%"puts "Jam : #{jam}"puts "Menit : #{mnt}"puts "Detik : #{dtk}"putsputs "#{hari}, #{tgl} #{bul} #{thn}"puts "Day-#{harke} (#{persen.round(4)}%)"puts waktu
5. C#
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di C# :
using System;public class Time {int Tahun;int Bulan;int Tanggal;int Harke;int Jam;int Menit;int Detik;public void DisplayDateAndTime() {Console.WriteLine($"Tahun \t\t\t\t\t: {Tahun}");Console.Write($"Bulan \t\t\t\t\t: {Bulan} ");Console.WriteLine("("+DateTime.Now.ToString("MMMM")+")");Console.WriteLine($"Tanggal \t\t\t\t: {Tanggal} ");Console.WriteLine($"Hari \t\t\t\t\t: "+DateTime.Now.ToString("dddd"));Console.WriteLine($"Hari ke (dalam Setahun) : {Harke} ");Console.WriteLine($"Jam \t\t\t\t\t: {Jam}");Console.WriteLine($"Menit \t\t\t\t\t: {Menit} ");Console.WriteLine($"Detik \t\t\t\t\t: {Detik} ");}public void DisplayCurrentTime() {Console.WriteLine(DateTime.Now.ToString("dddd, dd MMMM yyyy"));Console.WriteLine(DateTime.Now.ToString("HH:mm:ss"));System.Console.WriteLine("{0}:{1}:{2}", Jam, Menit, Detik);Console.WriteLine($"Day-{Harke}");}public Time(System.DateTime dt) {Tahun = dt.Year;Bulan = dt.Month;Tanggal = dt.Day;Jam = dt.Hour;Menit = dt.Minute;Detik = dt.Second;Harke = int.Parse(dt.DayOfYear.ToString());}}public class Penanggalan {static void Main(string[] args) {System.DateTime currentTime = System.DateTime.Now;Time waktu = new Time(currentTime);waktu.DisplayDateAndTime();Console.WriteLine("");waktu.DisplayCurrentTime();}}
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di C# (Dengan Persentase Tahun) :
using System;public class Time {int Leap;int Tahun;int Bulan;int Tanggal;int Harke;int Harmun;double Jam;double Menit;double Detik;double Persen;double Permun;double DateCal;public void DisplayDateAndTime() {Console.WriteLine($"Tahun : {Tahun}");Console.WriteLine($"Bulan : {Bulan} ("+DateTime.Now.ToString("MMMM")+")");Console.WriteLine($"Tanggal : {Tanggal}");Console.WriteLine($"Hari : "+DateTime.Now.ToString("dddd"));Console.WriteLine($"Hari ke (dalam Setahun) : {Harke}");Console.WriteLine($"Sisa Hari (Tahun depan) : {Harmun}");Console.WriteLine($"Persentase dalam Setahun : "+Math.Round(Persen, 6)+"%");Console.WriteLine($"Persentase Hitung Mundur : "+Math.Round(Permun, 6)+"%");Console.WriteLine($"Jam : {Jam}");Console.WriteLine($"Menit : {Menit}");Console.WriteLine($"Detik : {Detik}");}public void DisplayCurrentTime() {Console.WriteLine(DateTime.Now.ToString("dddd, dd MMMM yyyy"));Console.WriteLine(DateTime.Now.ToString("HH:mm:ss"));System.Console.WriteLine("{0}:{1}:{2}", Jam, Menit, Detik);Console.WriteLine($"Day-{Harke} ("+Math.Round(Persen, 4)+"%)");}public Time(System.DateTime dt) {Tahun = dt.Year;Bulan = dt.Month;Tanggal = dt.Day;Jam = dt.Hour;Menit = dt.Minute;Detik = dt.Second;if (Tahun % 400 == 0){Leap = 366;}else if (Tahun % 100 == 0){Leap = 365;}else if (Tahun % 4 == 0){Leap = 366;}else {Leap = 365;}Harke = int.Parse(dt.DayOfYear.ToString());Harmun = 1+Leap-Harke;DateCal = (Harke-1)+(Jam/24)+(Menit/1440)+(Detik/86400);Persen = (double)(100*DateCal/Leap);Permun = 100-Persen;}}public class Penanggalan {static void Main(string[] args) {System.DateTime currentTime = System.DateTime.Now;Time waktu = new Time(currentTime);waktu.DisplayDateAndTime();Console.WriteLine("");waktu.DisplayCurrentTime();}}
6. Java (Text-Based)
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di Java :
import java.util.*;import java.text.*;public class Penanggalan {public static void main(String[] args){int Leap, Tahun, Bulan, Tanggal;int Harmun;int Jam, Menit, Detik;float Persen, DateCal;Date month = new Date();SimpleDateFormat mn = new SimpleDateFormat("MMMMM");Date day = new Date();SimpleDateFormat dy = new SimpleDateFormat("EEEEE");Calendar cal = Calendar.getInstance();Tahun = cal.get(Calendar.YEAR);Bulan = cal.get(Calendar.MONTH)+1;Tanggal = cal.get(Calendar.DATE);Jam = cal.get(Calendar.HOUR);Menit = cal.get(Calendar.MINUTE);Detik = cal.get(Calendar.SECOND);System.out.println("Tahun : " + Tahun);System.out.println("Bulan : " + Bulan+" ("+mn.format(month)+")");System.out.println("Tanggal : " + Tanggal);System.out.println("Hari : " + dy.format(day));System.out.println("Jam : " + Jam);System.out.println("Menit : " + Menit);System.out.println("Detik : " + Detik);System.out.println();String shortPattern = "dd-MM-yyyy";SimpleDateFormat simpleDateFormat = new SimpleDateFormat(shortPattern);String shortDate = simpleDateFormat.format(new Date());System.out.println(shortDate);String longPattern = "EEEEE, dd MMMMM yyyy";SimpleDateFormat dateFormat = new SimpleDateFormat(longPattern);String longDate = dateFormat.format(new Date());System.out.println(longDate);String pattern = "HH:mm:ss";SimpleDateFormat timeFormat = new SimpleDateFormat(pattern);String time = timeFormat.format(new Date());System.out.println(time);//Date harke = new Date();//String format = dateFormat.format(harke);//System.out.printf("Day-%Tj\n", harke, harke);String dayYear = "D";SimpleDateFormat dayinayear = new SimpleDateFormat(dayYear);String harke = dayinayear.format(new Date());System.out.println("Day-"+harke);}}
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di Java (Dengan Persentase Tahun) :
import java.util.*;import java.util.Date;import java.text.*;import java.math.RoundingMode;public class Penanggalan {static int Leap, Tahun, Bulan, Tanggal;static int Harmun, Harke;static double Jam, Menit, Detik;static double Persen, Permun, DateCal;public void DateDisplay() {Date month = new Date();SimpleDateFormat mn = new SimpleDateFormat("MMMMM");Date day = new Date();SimpleDateFormat dy = new SimpleDateFormat("EEEEE");Calendar cal = Calendar.getInstance();Tahun = cal.get(Calendar.YEAR);Bulan = cal.get(Calendar.MONTH)+1;Tanggal = cal.get(Calendar.DATE);System.out.println("Tahun : " + Tahun);System.out.println("Bulan : " + Bulan+" ("+mn.format(month)+")");System.out.println("Tanggal : " + Tanggal);System.out.println("Hari : " + dy.format(day));}public void TimeDisplay() {Calendar tme = Calendar.getInstance();DecimalFormat wkt = new DecimalFormat("#");Jam = tme.get(Calendar.HOUR_OF_DAY);Menit = tme.get(Calendar.MINUTE);Detik = tme.get(Calendar.SECOND);System.out.println("Jam : " + wkt.format(Jam));System.out.println("Menit : " + wkt.format(Menit));System.out.println("Detik : " + wkt.format(Detik));}public static void main(String args[]) {Penanggalan tanggalWaktu = new Penanggalan();Calendar dt = Calendar.getInstance();tanggalWaktu.Tahun = dt.get(Calendar.YEAR);tanggalWaktu.Bulan = dt.get(Calendar.MONTH)+1;tanggalWaktu.Tanggal = dt.get(Calendar.DATE);tanggalWaktu.Jam = dt.get(Calendar.HOUR_OF_DAY);tanggalWaktu.Menit = dt.get(Calendar.MINUTE);tanggalWaktu.Detik = dt.get(Calendar.SECOND);String shortPattern = "dd-MM-yyyy";SimpleDateFormat simpleDateFormat = new SimpleDateFormat(shortPattern);String shortDate = simpleDateFormat.format(new Date());String longPattern = "EEEEE, dd MMMMM yyyy";SimpleDateFormat dateFormat = new SimpleDateFormat(longPattern);String longDate = dateFormat.format(new Date());String pattern = "HH:mm:ss";SimpleDateFormat timeFormat = new SimpleDateFormat(pattern);String time = timeFormat.format(new Date());String dayYear = "D";SimpleDateFormat dayinayear = new SimpleDateFormat(dayYear);String harke = dayinayear.format(new Date());if (Tahun % 400 == 0){Leap = 366;}else if (Tahun % 100 == 0){Leap = 365;}else if (Tahun % 4 == 0){Leap = 366;}else {Leap = 365;}Harke = Integer.parseInt(harke);Harmun = 1+Leap-Harke;DateCal = (Harke-1)+(Jam/24)+(Menit/1440)+(Detik/86400);Persen = 100*DateCal/Leap;Permun = 100-Persen;DecimalFormat df1 = new DecimalFormat("#.######");DecimalFormat df2 = new DecimalFormat("#.####");tanggalWaktu.DateDisplay();System.out.println("Hari ke (dalam Setahun) : " + Harke);System.out.println("Sisa Hari (Tahun depan) : " + Harmun);System.out.println("Persentase dalam Setahun : " + df1.format(Persen)+"%");System.out.println("Persentase Hitung Mundur : " + df1.format(Permun)+"%");tanggalWaktu.TimeDisplay();System.out.println();System.out.println(longDate);System.out.println(shortDate);System.out.println("Day-"+harke+" ("+df2.format(Persen)+"%)");System.out.println(time);}}
Atau yang ini (Persentase Kasar) :
import java.util.*;import java.util.Date;import java.text.*;import java.math.RoundingMode;public class Penanggalan {int Leap, Tahun, Bulan, Tanggal;int Harmun, Harke;float Jam, Menit, Detik;float Persen, Permun, DateCal;public void DateDisplay() {Date month = new Date();SimpleDateFormat mn = new SimpleDateFormat("MMMMM");Date day = new Date();SimpleDateFormat dy = new SimpleDateFormat("EEEEE");Calendar cal = Calendar.getInstance();Tahun = cal.get(Calendar.YEAR);Bulan = cal.get(Calendar.MONTH)+1;Tanggal = cal.get(Calendar.DATE);System.out.println("Tahun : " + Tahun);System.out.println("Bulan : " + Bulan+" ("+mn.format(month)+")");System.out.println("Tanggal : " + Tanggal);System.out.println("Hari : " + dy.format(day));}public void DisplayCurrentTime(){String shortPattern = "dd-MM-yyyy";SimpleDateFormat simpleDateFormat = new SimpleDateFormat(shortPattern);String shortDate = simpleDateFormat.format(new Date());String longPattern = "EEEEE, dd MMMMM yyyy";SimpleDateFormat dateFormat = new SimpleDateFormat(longPattern);String longDate = dateFormat.format(new Date());String pattern = "HH:mm:ss";SimpleDateFormat timeFormat = new SimpleDateFormat(pattern);String time = timeFormat.format(new Date());String dayYear = "D";SimpleDateFormat dayinayear = new SimpleDateFormat(dayYear);String harke = dayinayear.format(new Date());if (Tahun % 400 == 0){Leap = 366;}else if (Tahun % 100 == 0){Leap = 365;}else if (Tahun % 4 == 0){Leap = 366;}else {Leap = 365;}Harke = Integer.parseInt(harke);Harmun = 1+Leap-Harke;DateCal = (Harke-1)+((float)Jam/24)+((float)Menit/1440)+((float)Detik/86400);Persen = (float)(100*DateCal/Leap);Permun = 100-Persen;DecimalFormat df = new DecimalFormat("#.####");System.out.println("Hari ke (dalam Setahun) : " + Harke);System.out.println("Sisa Hari (Tahun depan) : " + Harmun);System.out.println("Persentase dalam Setahun : " + Persen+"%");System.out.println("Persentase Hitung Mundur : " + Permun+"%");System.out.println();System.out.println(shortDate);System.out.println(longDate);System.out.println(time);System.out.print("Day-"+harke);System.out.print(" ("+df.format(Persen)+"%)");}public void TimeDisplay() {Calendar tme = Calendar.getInstance();DecimalFormat wkt = new DecimalFormat("#");Jam = tme.get(Calendar.HOUR_OF_DAY);Menit = tme.get(Calendar.MINUTE);Detik = tme.get(Calendar.SECOND);System.out.println("Jam : " + wkt.format(Jam));System.out.println("Menit : " + wkt.format(Menit));System.out.println("Detik : " + wkt.format(Detik));}public static void main(String args[]) {Penanggalan tanggalWaktu = new Penanggalan();tanggalWaktu.DateDisplay();tanggalWaktu.TimeDisplay();tanggalWaktu.DisplayCurrentTime();}}
7. Java (GUI)
Referensi : JTextField atau JLabel, JProgressBar
a. Tanpa Persentase Tahun
import javax.swing.*;import java.awt.*;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class Penanggalan extends JFrame {private JLabel yearLabel, monthLabel, dateLabel, dayLabel, hourLabel, minuteLabel, secondLabel;private JLabel shortDateLabel, longDateLabel, timeLabel, dayOfYearLabel;public Penanggalan() {setTitle("Penanggalan");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLayout(new GridLayout(8, 2));setBounds(20, 50, 300, 200);yearLabel = new JLabel("Tahun :");monthLabel = new JLabel("Bulan :");dateLabel = new JLabel("Tanggal :");dayLabel = new JLabel("Hari :");hourLabel = new JLabel("Jam :");minuteLabel = new JLabel("Menit :");secondLabel = new JLabel("Detik :");shortDateLabel = new JLabel();longDateLabel = new JLabel();timeLabel = new JLabel();dayOfYearLabel = new JLabel();add(yearLabel);add(monthLabel);add(dateLabel);add(dayLabel);add(hourLabel);add(minuteLabel);add(secondLabel);add(shortDateLabel);add(longDateLabel);add(timeLabel);add(dayOfYearLabel);updateDateTime(); // Initial updateTimer timer = new Timer(1000, e -> {updateDateTime(); // Update every second});timer.start();setVisible(true);}private void updateDateTime() {Calendar cal = Calendar.getInstance();int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH) + 1;int date = cal.get(Calendar.DATE);int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);int hour = cal.get(Calendar.HOUR);int minute = cal.get(Calendar.MINUTE);int second = cal.get(Calendar.SECOND);yearLabel.setText("Tahun: " + year);monthLabel.setText("Bulan: " + month + " (" + getMonthName(month) + ")");dateLabel.setText("Tanggal: " + date);dayLabel.setText("Hari: " + getDayOfWeekName(dayOfWeek));hourLabel.setText("Jam: " + hour);minuteLabel.setText("Menit: " + minute);secondLabel.setText("Detik: " + second);SimpleDateFormat shortDateFormat = new SimpleDateFormat("dd-MM-yyyy");String shortDate = shortDateFormat.format(new Date());shortDateLabel.setText(shortDate);SimpleDateFormat longDateFormat = new SimpleDateFormat("EEEE, dd MMMM yyyy");String longDate = longDateFormat.format(new Date());longDateLabel.setText(longDate);SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");String time = timeFormat.format(new Date());timeLabel.setText(time);SimpleDateFormat dayOfYearFormat = new SimpleDateFormat("D");String dayOfYear = dayOfYearFormat.format(new Date());dayOfYearLabel.setText("Day-" + dayOfYear);}private String getMonthName(int month) {SimpleDateFormat monthFormat = new SimpleDateFormat("MMMMM");Calendar cal = Calendar.getInstance();cal.set(Calendar.MONTH, month - 1);return monthFormat.format(cal.getTime());}private String getDayOfWeekName(int dayOfWeek) {SimpleDateFormat dayOfWeekFormat = new SimpleDateFormat("EEEE");Calendar cal = Calendar.getInstance();cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);return dayOfWeekFormat.format(cal.getTime());}public static void main(String[] args) {SwingUtilities.invokeLater(new Runnable() {public void run() {new Penanggalan();}});}}
Hasil Output :
b. Dengan Persentase Tahun
import javax.swing.*;import java.awt.*;import java.text.DecimalFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class Penanggalan extends JFrame {private JLabel yearLabel, monthLabel, dateLabel, dayLabel, dayOfYearLabel, daysLeftLabel;private JLabel percentageLabel, reversePercentageLabel, hourLabel, minuteLabel, secondLabel;private JLabel longDateLabel, shortDateLabel, dayOfYearPercentLabel, timeLabel;public Penanggalan() {setTitle("Penanggalan");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setLayout(new GridLayout(9, 2));setBounds(20, 50, 500, 300);yearLabel = new JLabel("Tahun:");monthLabel = new JLabel("Bulan:");dateLabel = new JLabel("Tanggal:");dayLabel = new JLabel("Hari:");dayOfYearLabel = new JLabel("Hari ke (dalam Setahun):");daysLeftLabel = new JLabel("Sisa Hari (Tahun depan):");percentageLabel = new JLabel("Persentase dalam Setahun:");reversePercentageLabel = new JLabel("Persentase Hitung Mundur:");hourLabel = new JLabel("Jam:");minuteLabel = new JLabel("Menit:");secondLabel = new JLabel("Detik:");longDateLabel = new JLabel();shortDateLabel = new JLabel();dayOfYearPercentLabel = new JLabel();timeLabel = new JLabel();add(yearLabel);add(monthLabel);add(dateLabel);add(dayLabel);add(dayOfYearLabel);add(daysLeftLabel);add(percentageLabel);add(reversePercentageLabel);add(hourLabel);add(minuteLabel);add(secondLabel);add(longDateLabel);add(shortDateLabel);add(dayOfYearPercentLabel);add(timeLabel);updateDateTime(); // Initial updateTimer timer = new Timer(1000, e -> {updateDateTime(); // Update every second});timer.start();setVisible(true);}private void updateDateTime() {Calendar cal = Calendar.getInstance();int year = cal.get(Calendar.YEAR);int month = cal.get(Calendar.MONTH) + 1;int date = cal.get(Calendar.DATE);int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);double hour = cal.get(Calendar.HOUR_OF_DAY);double minute = cal.get(Calendar.MINUTE);double second = cal.get(Calendar.SECOND);yearLabel.setText("Tahun: " + year);monthLabel.setText("Bulan: " + month + " (" + getMonthName(month) + ")");dateLabel.setText("Tanggal: " + date);dayLabel.setText("Hari: " + getDayOfWeekName(dayOfWeek));dayOfYearLabel.setText("Hari ke (dalam Setahun): " + dayOfYear);int daysLeft = getDaysLeft(year, dayOfYear);daysLeftLabel.setText("Sisa Hari (Tahun depan): " + daysLeft);hourLabel.setText("Jam: " + (int)hour);minuteLabel.setText("Menit: " + (int)minute);secondLabel.setText("Detik: " + (int)second);double percentOfYear = (dayOfYear - 1) + (hour / 24) + (minute / 1440) + (second / 86400);double percentage = (percentOfYear / 365) * 100;double reversePercentage = 100 - percentage;DecimalFormat df = new DecimalFormat("#.######");percentageLabel.setText("Persentase dalam Setahun: " + df.format(percentage) + "%");reversePercentageLabel.setText("Persentase Hitung Mundur: " + df.format(reversePercentage) + "%");SimpleDateFormat longDateFormat = new SimpleDateFormat("EEEE, dd MMMMM yyyy");SimpleDateFormat shortDateFormat = new SimpleDateFormat("dd-MM-yyyy");SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");longDateLabel.setText(longDateFormat.format(new Date()));shortDateLabel.setText(shortDateFormat.format(new Date()));dayOfYearPercentLabel.setText("Day-" + dayOfYear + " (" + df.format(percentage) + "%)");timeLabel.setText(timeFormat.format(new Date()));}private String getMonthName(int month) {String[] monthNames = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};return monthNames[month];}private String getDayOfWeekName(int dayOfWeek) {String[] dayNames = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};return dayNames[dayOfWeek - 1];}private int getDaysLeft(int year, int dayOfYear) {Calendar cal = Calendar.getInstance();cal.set(Calendar.YEAR, year + 1);cal.set(Calendar.DAY_OF_YEAR, 1);cal.add(Calendar.DAY_OF_YEAR, -1);int daysInYear = cal.get(Calendar.DAY_OF_YEAR);return daysInYear - dayOfYear;}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {new Penanggalan();});}}
Hasil Output :
c. Dengan Persentase menggunakan Progress Bar
Hasil Output :
8. C++
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di C++ :
#include <iostream>#include <iomanip>#include <ctime>using namespace std;const string currentMonth() {time_t nowMn = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowMn);strftime(buf, sizeof(buf), "%B", &tstruct);return buf;}const string currentDay() {time_t nowDy = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowDy);strftime(buf, sizeof(buf), "%A", &tstruct);return buf;}const string currentDate() {time_t nowDt = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowDt);strftime(buf, sizeof(buf), "%A, %d %B %G", &tstruct);return buf;}const string currentTime() {time_t nowTm = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowTm);strftime(buf, sizeof(buf), "%H:%M:%S", &tstruct);return buf;}const string dayInAYear() {time_t daYr = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&daYr);strftime(buf, sizeof(buf), "%j", &tstruct);return buf;}int main() {int thn, bln, tgl, har;int harke;int jam, mnt, dtk;string bul, hari, waktu, tanggal;float persen;time_t ttime = time(0);tm *local_time = localtime(&ttime);thn = 1900 + local_time->tm_year;bln = 1 + local_time->tm_mon;bul = currentMonth();tgl = local_time->tm_mday;har = local_time->tm_wday;hari = currentDay();harke = stoi(dayInAYear());tanggal = currentDate();waktu = currentTime();jam = local_time->tm_hour;mnt = local_time->tm_min;dtk = local_time->tm_sec;if (hari == "Sunday"){har = 7;}cout<<"Tahun : "<<thn<<endl;cout<<"Bulan : "<<bln<<" ("<<bul<<")"<<endl;cout<<"Tanggal : "<<tgl<<endl;cout<<"Hari : "<<har<<" ("<<hari<<")"<<endl;cout<<"Hari ke (dalam Setahun) : "<<harke<<endl;cout<<"Jam : "<<jam<<endl;cout<<"Menit : "<<mnt<<endl;cout<<"Detik : "<<dtk<<endl;cout<<endl;//cout<<tanggal<<endl;cout<<hari<<", "<<tgl<<" "<<bul<<" "<<thn<<endl;cout<<"Day-"<<harke<<endl;cout<<waktu<<endl;return 0;}
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di C++ (Dengan Persentase Tahun) :
#include <iostream>#include <iomanip>#include <ctime>using namespace std;const string currentMonth() {time_t nowMn = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowMn);strftime(buf, sizeof(buf), "%B", &tstruct);return buf;}const string currentDay() {time_t nowDy = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowDy);strftime(buf, sizeof(buf), "%A", &tstruct);return buf;}const string currentDate() {time_t nowDt = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowDt);strftime(buf, sizeof(buf), "%A, %d %B %G", &tstruct);return buf;}const string currentTime() {time_t nowTm = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&nowTm);strftime(buf, sizeof(buf), "%H:%M:%S", &tstruct);return buf;}const string dayInAYear() {time_t daYr = time(0);struct tm tstruct;char buf[80];tstruct = *localtime(&daYr);strftime(buf, sizeof(buf), "%j", &tstruct);return buf;}int main() {int leap, thn, bln, tgl, har;int harmun, harke;int jam, mnt, dtk;string bul, hari, waktu, tanggal;float dateCal, persen, permun;time_t ttime = time(0);tm *local_time = localtime(&ttime);thn = 1900 + local_time->tm_year;bln = 1 + local_time->tm_mon;bul = currentMonth();tgl = local_time->tm_mday;har = local_time->tm_wday;hari = currentDay();harke = stoi(dayInAYear());tanggal = currentDate();waktu = currentTime();jam = local_time->tm_hour;mnt = local_time->tm_min;dtk = local_time->tm_sec;if (thn % 400 == 0){leap = 366;}else if (thn % 100 == 0){leap = 365;}else if (thn % 4 == 0){leap = 366;}else {leap = 365;}dateCal = (harke-1)+((float)jam/24)+((float)mnt/1440)+((float)dtk/86400);persen = (float)(100*dateCal/leap);harmun = 1+leap-harke;permun = 100-persen;if (hari == "Sunday"){har = 7;}cout<<"Tahun : "<<thn<<endl;cout<<"Bulan : "<<bln<<" ("<<bul<<")"<<endl;cout<<"Tanggal : "<<tgl<<endl;cout<<"Hari : "<<har<<" ("<<hari<<")"<<endl;cout<<"Hari ke (dalam Setahun) : "<<harke<<endl;cout<<"Sisa Hari (Tahun depan) : "<<harmun<<endl;cout<<"Persentase dalam Setahun : "<<fixed<<setprecision(6)<<persen<<"%"<<endl;cout<<"Persentase Hitung Mundur : "<<fixed<<setprecision(6)<<permun<<"%"<<endl;cout<<"Jam : "<<jam<<endl;cout<<"Menit : "<<mnt<<endl;cout<<"Detik : "<<dtk<<endl;cout<<endl;//cout<<tanggal<<endl;cout<<hari<<", "<<tgl<<" "<<bul<<" "<<thn<<endl;cout<<"Day-"<<harke<<" ("<<fixed<<setprecision(4)<<persen<<"%)"<<endl;cout<<waktu<<endl;return 0;}
9. C
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di Pemrograman C :
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>int main(){int thn, bln, tgl, har;int harke;int jam, mnt, dtk;char bufMon[32];struct tm *ts1;size_t last1;time_t nowMn = time(NULL);ts1 = localtime(&nowMn);last1 = strftime(bufMon, 32, "%B", ts1);bufMon[last1] = '\0';char bufDay[32];struct tm *ts2;size_t last2;time_t nowDy = time(NULL);ts2 = localtime(&nowDy);last2 = strftime(bufDay, 32, "%A", ts2);bufDay[last2] = '\0';char bufDate[32];struct tm *ts3;size_t last3;time_t nowDt = time(NULL);ts3 = localtime(&nowDt);last3 = strftime(bufDate, 32, "%A, %d %B %G", ts3);char bufTime[32];struct tm *ts4;size_t last4;time_t nowTm = time(NULL);ts4 = localtime(&nowTm);last4 = strftime(bufTime, 32, "%H:%M:%S", ts4);bufTime[last4] = '\0';char bufDayInYear[32];struct tm *ts5;size_t last5;time_t daYr = time(NULL);ts5 = localtime(&daYr);last5 = strftime(bufDayInYear, 32, "%j", ts5);time_t now;time(&now);struct tm *local_time = localtime(&now);thn = 1900 + local_time->tm_year;bln = 1 + local_time->tm_mon;tgl = local_time->tm_mday;har = local_time->tm_wday;jam = local_time->tm_hour;mnt = local_time->tm_min;dtk = local_time->tm_sec;printf("Tahun : %d\n", thn);printf("Bulan : %d (%s)\n", bln, bufMon);printf("Tanggal : %d\n", tgl);printf("Hari : %d (%s)\n", har, bufDay);printf("Hari ke (dalam Setahun) : %s\n", bufDayInYear);printf("Jam : %d\n", jam);printf("Menit : %d\n", mnt);printf("Detik : %d\n", dtk);printf("\n");printf("%s, %02d %s %d\n", bufDay, tgl, bufMon, thn);//printf("%s\n", bufDate);printf("Day-%s\n", bufDayInYear);printf("%s", bufTime);return 0;}
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di Pemrograman C (Dengan Persentase Tahun) :
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>int main(){int leap, thn, bln, tgl, har;int harke, harmun;int jam, mnt, dtk;double dateCal, persen, permun;char bufMon[32];struct tm *ts1;size_t last1;time_t nowMn = time(NULL);ts1 = localtime(&nowMn);last1 = strftime(bufMon, 32, "%B", ts1);bufMon[last1] = '\0';char bufDay[32];struct tm *ts2;size_t last2;time_t nowDy = time(NULL);ts2 = localtime(&nowDy);last2 = strftime(bufDay, 32, "%A", ts2);bufDay[last2] = '\0';char bufDate[32];struct tm *ts3;size_t last3;time_t nowDt = time(NULL);ts3 = localtime(&nowDt);last3 = strftime(bufDate, 32, "%A, %d %B %G", ts3);char bufTime[32];struct tm *ts4;size_t last4;time_t nowTm = time(NULL);ts4 = localtime(&nowTm);last4 = strftime(bufTime, 32, "%H:%M:%S", ts4);bufTime[last4] = '\0';time_t now;time(&now);struct tm *local_time = localtime(&now);thn = 1900 + local_time->tm_year;bln = 1 + local_time->tm_mon;tgl = local_time->tm_mday;har = local_time->tm_wday;harke = 1 + local_time->tm_yday;jam = local_time->tm_hour;mnt = local_time->tm_min;dtk = local_time->tm_sec;if (thn % 400 == 0){leap = 366;}else if (thn % 100 == 0){leap = 365;}else if (thn % 4 == 0){leap = 366;}else {leap = 365;}dateCal = (harke-1)+((double)jam/24)+((double)mnt/1440)+((double)dtk/86400);persen = (double)(100*dateCal/leap);harmun = 1+leap-harke;permun = 100-persen;printf("Tahun : %d\n", thn);printf("Bulan : %d (%s)\n", bln, bufMon);printf("Tanggal : %d\n", tgl);printf("Hari : %d (%s)\n", har, bufDay);printf("Hari ke (dalam Setahun) : %d\n", harke);printf("Sisa Hari (Tahun depan) : %d\n", harmun);printf("Persentase dalam Setahun : %f%\n", persen);printf("Persentase Hitung Mundur : %f%\n", permun);printf("Jam : %d\n", jam);printf("Menit : %d\n", mnt);printf("Detik : %d\n", dtk);printf("\n");printf("%s, %02d %s %d\n", bufDay, tgl, bufMon, thn);printf("Day-%d (%.4f%)\n", harke, persen);printf("%s", bufTime);return 0;}
10. PHP (Tanpa HTML / Text-Based)
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di PHP :
<?php$thn = date("Y");$bln = date("n");$bul = date("F");$tgl = date("j");$hari = date("l");$harke = date("z");$jam = date("H");$mnt = date("i");$dtk = date("s");echo "Tahun : ".$thn."\n";echo "Bulan : ".$bln." (".$bul.")"."\n";echo "Tanggal : ".$tgl."\n";echo "Hari : ".$hari."\n";echo "Hari ke (dalam Setahun) : ".$harke."\n";echo "Jam : ".$jam."\n";echo "Menit : ".$mnt."\n";echo "Detik : ".$dtk."\n";echo "\n".date("l, j F Y")."\n";echo "Day-".$harke."\n";echo date("H:i:s");?>
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di PHP (Dengan Persentase Tahun) :
<?php$thn = date("Y");$bln = date("n");$bul = date("F");$tgl = date("j");$hari = date("l");$harke = date("z")+1;$jam = date("H");$mnt = date("i");$dtk = date("s");if ($thn % 400 == 0){$leap = 366;}elseif ($thn % 100 == 0){$leap = 365;}elseif ($thn % 4 == 0){$leap = 366;}else {$leap = 365;}$dateCal = ($harke-1)+($jam/24)+($mnt/1440)+($dtk/86400);$persen = (float)(100*$dateCal/$leap);$harmun = 1+$leap-$harke;$permun = 100-$persen;echo "Tahun : ".$thn."\n";echo "Bulan : ".$bln." (".$bul.")"."\n";echo "Tanggal : ".$tgl."\n";echo "Hari : ".$hari."\n";echo "Hari ke (dalam Setahun) : ".$harke."\n";echo "Sisa Hari (Tahun depan) : ".$harmun."\n";echo "Persentase dalam Setahun : ".round($persen,6)."% \n";echo "Persentase Hitung Mundur : ".round($permun,6)."% \n";echo "Jam : ".$jam."\n";echo "Menit : ".$mnt."\n";echo "Detik : ".$dtk."\n";echo "\n".date("l, j F Y")."\n";echo date("H:i:s")."\n";echo "Day-".$harke." (".round($persen,4)."%)";?>
11. PHP (Dengan HTML)
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di PHP dengan HTML :
<!DOCTYPE html><html><body><?php$thn = date("Y");$bln = date("n");$bul = date("F");$tgl = date("j");$hari = date("l");$harke = date("z");$jam = date("H");$mnt = date("i");$dtk = date("s");echo "Tahun : ".$thn."<br>";echo "Bulan : ".$bln." (".$bul.")"."<br>";echo "Tanggal : ".$tgl."<br>";echo "Hari : ".$hari."<br>";echo "Hari ke (dalam Setahun) : ".$harke."<br>";echo "Jam : ".$jam."<br>";echo "Menit : ".$mnt."\n"."<br>";echo "Detik : ".$dtk."\n"."<br>";echo "<br>";echo "\n".date("l, j F Y")."\n"."<br>";echo "Day-".$harke."<br>";echo date("H:i:s");?></body></html>
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di PHP dengan HTML (Dengan Persentase Tahun) :
<!DOCTYPE html><html><body><?php$thn = date("Y");$bln = date("n");$bul = date("F");$tgl = date("j");$hari = date("l");$harke = date("z")+1;$jam = date("H");$mnt = date("i");$dtk = date("s");if ($thn % 400 == 0){$leap = 366;}elseif ($thn % 100 == 0){$leap = 365;}elseif ($thn % 4 == 0){$leap = 366;}else {$leap = 365;}$dateCal = ($harke-1)+($jam/24)+($mnt/1440)+($dtk/86400);$persen = (float)(100*$dateCal/$leap);$harmun = 1+$leap-$harke;$permun = 100-$persen;echo "Tahun : ".$thn."<br>";echo "Bulan : ".$bln." (".$bul.")"."<br>";echo "Tanggal : ".$tgl."<br>";echo "Hari : ".$hari."<br>";echo "Hari ke (dalam Setahun) : ".$harke."<br>";echo "Sisa Hari (Tahun depan) : ".$harmun."<br>";echo "Persentase dalam Setahun : ".round($persen,6)."% <br>";echo "Persentase Hitung Mundur : ".round($permun,6)."% <br>";echo "Jam : ".$jam."<br>";echo "Menit : ".$mnt."\n"."<br>";echo "Detik : ".$dtk."\n"."<br>";echo "<br>";echo "\n".date("l, j F Y")."\n"."<br>";echo date("H:i:s")."<br>";echo "Day-".$harke." (".round($persen,4)."%)";?></body></html>
12. JavaScript Murni (Tanpa HTML)
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di JavaScript :
const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}console.log("Tahun : "+tahun);console.log("Bulan : "+bulan+" ("+bul+")");console.log("Tanggal : "+tanggal);console.log("Hari : "+har+" ("+hari+")");console.log("Hari ke (dalam Setahun) : "+harke);console.log("Jam : "+jam);console.log("Menit : "+menit);console.log("Detik : "+detik);console.log("\n"+hari+", "+tanggal+" "+bul+" "+tahun);console.log(waktu);console.log("Day-"+harke);
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di JavaScript (Dengan Persentase Tahun) :
const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);if (tahun % 400 == 0){leap = 366;}else if (tahun % 100 == 0){leap = 365;}else if (tahun % 4 == 0){leap = 366;}else {leap = 365;}var persen = 100/leap*(harke-1+(jam/24)+(menit/1440)+(detik/86400));var harmun = 1+leap-harke;var permun = 100-persen;var num1 = persen;var num2 = permun;const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}console.log("Tahun : "+tahun);console.log("Bulan : "+bulan+" ("+bul+")");console.log("Tanggal : "+tanggal);console.log("Hari : "+har+" ("+hari+")");console.log("Hari ke (dalam Setahun) : "+harke);console.log("Sisa Hari (Tahun depan) : "+harmun);console.log("Persentase dalam Setahun : "+num1.toFixed(6)+"%");console.log("Persentase Hitung Mundur : "+num2.toFixed(6)+"%");console.log("Jam : "+jam);console.log("Menit : "+menit);console.log("Detik : "+detik);console.log("\n"+hari+", "+tanggal+" "+bul+" "+tahun);console.log(waktu);console.log("Day-"+harke+" ("+num1.toFixed(4)+"%)");
13. HTML dan JavaScript
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di JavaScript dengan HTML :
<!DOCTYPE html><html><body><h2>Program Sistem Penanggalan </h2><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.write("Tahun : "+tahun+"<br/>");document.write("Bulan : "+bulan+" ("+bul+") <br/>");document.write("Tanggal : "+tanggal+"<br/>");document.write("Hari : "+har+" ("+hari+") <br/>");document.write("Hari ke (dalam Setahun) : "+harke+"<br/>");document.write("Jam : "+jam+"<br/>");document.write("Menit : "+menit+"<br/>");document.write("Detik : "+detik+"<br/>");document.write("<br/>"+hari+", "+tanggal+" "+bul+" "+tahun+"<br/>");document.write(waktu+"<br/>");document.write("Day-"+harke+"<br/>");</script></body></html>
Atau yang ini (Bentuk lain dari Fungsi Output dari JavaScript dan HTML) :
<!DOCTYPE html><html><body><h2>Program Sistem Penanggalan</h2><p id="datetime"></p><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.getElementById("datetime").innerHTML ="Tahun : "+tahun+"<br>"+"Bulan : "+bulan+" ("+bul+") <br/>"+"Tanggal : "+tanggal+"<br>"+"Hari : "+har+" ("+hari+") <br/>"+"Hari ke (dalam Setahun) : "+harke+"<br>"+"Jam : "+jam+"<br>"+"Menit : "+menit+"<br>"+"Detik : "+detik+"<br>"+"<br/>"+hari+", "+tanggal+" "+bul+" "+tahun+"<br/>"+waktu+"<br/>"+"Day-"+harke+"<br/>";</script></body></html>
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di JavaScript dengan HTML (Dengan Persentase Tahun) :
<!DOCTYPE html><html><body><h2>Program Sistem Penanggalan </h2><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);if (tahun % 400 == 0){leap = 366;}else if (tahun % 100 == 0){leap = 365;}else if (tahun % 4 == 0){leap = 366;}else {leap = 365;}var persen = 100/leap*(harke-1+(jam/24)+(menit/1440)+(detik/86400));var harmun = 1+leap-harke;var permun = 100-persen;var num1 = persen;var num2 = permun;const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.write("Tahun : "+tahun+"<br/>");document.write("Bulan : "+bulan+" ("+bul+") <br/>");document.write("Tanggal : "+tanggal+"<br/>");document.write("Hari : "+har+" ("+hari+") <br/>");document.write("Hari ke (dalam Setahun) : "+harke+"<br/>");document.write("Sisa Hari (Tahun depan) : "+harmun+"<br/>");document.write("Persentase dalam Setahun : "+num1.toFixed(6)+"% <br/>");document.write("Persentase Hitung Mundur : "+num2.toFixed(6)+"% <br/>");document.write("Jam : "+jam+"<br/>");;document.write("Menit : "+menit+"<br/>");document.write("Detik : "+detik+"<br/>");document.write("<br/>"+hari+", "+tanggal+" "+bul+" "+tahun+"<br/>");document.write(waktu+"<br/>");document.write("Day-"+harke+" ("+num1.toFixed(4)+"%)");</script></body></html>
Atau yang ini (Bentuk lain dari Fungsi Output dari JavaScript dan HTML) :
<!DOCTYPE html><html><body><h2>Program Sistem Penanggalan</h2><p id="datetime"></p><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0"+jam).slice(-2)+":"+("0"+menit).slice(-2)+":"+("0"+detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);if (tahun % 400 == 0){leap = 366;}else if (tahun % 100 == 0){leap = 365;}else if (tahun % 4 == 0){leap = 366;}else {leap = 365;}var persen = 100/leap*(harke-1+(jam/24)+(menit/1440)+(detik/86400));var harmun = 1+leap-harke;var permun = 100-persen;var num1 = persen;var num2 = permun;const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.getElementById("datetime").innerHTML ="Tahun : "+tahun+"<br>"+"Bulan : "+bulan+" ("+bul+") <br/>"+"Tanggal : "+tanggal+"<br>"+"Hari : "+har+" ("+hari+") <br/>"+"Hari ke (dalam Setahun) : "+harke+"<br>"+"Sisa Hari (Tahun depan) : "+harmun+"<br>"+"Persentase dalam Setahun : "+num1.toFixed(6)+"% <br/>"+"Persentase Hitung Mundur : "+num2.toFixed(6)+"% <br/>"+"Jam : "+jam+"<br>"+"Menit : "+menit+"<br>"+"Detik : "+detik+"<br>"+"<br/>"+hari+", "+tanggal+" "+bul+" "+tahun+"<br/>"+waktu+"<br/>"+"Day-"+harke+" ("+num1.toFixed(4)+"%)";</script></body></html>
14. HTML, CSS, dan JavaScript
a. Tanpa Persentase Tahun
Lebar dengan menggunakan Persentase :
<!DOCTYPE html><html><head><style>table {font-family: arial, sans-serif;border-collapse: collapse;width: 100%;}td {border: 1px solid #c7c7c7;text-align: left;padding: 8px;width: 30%;}th {border: 1px solid #c7c7c7;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #f2f2f2;}tr:hover {background-color: #dddddd;}tr:nth-child(even) {background-color: #dddddd;}</style></head><body><h2>Tabel Sistem Penanggalan</h2><table style="width:35%"><tr><th style="width:50%">Tahun</th><td id="datetime-year"></td></tr><tr><th style="width:50%">Bulan</th><td id="datetime-month"></td></tr><tr><th style="width:50%">Tanggal</th><td id="datetime-date"></td></tr><tr><th style="width:50%">Hari</th><td id="datetime-day"></td></tr><tr><th style="width:50%">Hari ke (dalam Setahun)</th><td id="datetime-dayinyear"></td></tr><tr><th style="width:50%">Jam</th><td id="datetime-hour"></td></tr><tr><th style="width:50%">Menit</th><td id="datetime-minute"></td></tr><tr><th style="width:50%">Detik</th><td id="datetime-second"></td></tr></table><br></br><h2>Info Tanggal</h2><table style="width:35%"><tr><th style="width:40%">Hari dan Tanggal</th><td id="datetime-daydate"></td></tr><tr><th style="width:40%">Waktu</th><td id="datetime-time"></td></tr><tr><th style="width:40%">Hari ke</th><td id="datetime-dayinyear2"></td></tr></table><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.getElementById("datetime-daydate").innerHTML = hari+", "+tanggal+" "+bul+" "+tahun;document.getElementById("datetime-time").innerHTML = waktu;document.getElementById("datetime-year").innerHTML = tahun;document.getElementById("datetime-month").innerHTML = bul;document.getElementById("datetime-date").innerHTML = tanggal;document.getElementById("datetime-day").innerHTML = hari;document.getElementById("datetime-dayinyear").innerHTML = harke;document.getElementById("datetime-dayinyear2").innerHTML = harke;document.getElementById("datetime-hour").innerHTML = jam;document.getElementById("datetime-minute").innerHTML = menit;document.getElementById("datetime-second").innerHTML = detik;</script></body></html>
Lebar dengan menggunakan Piksel (px) :
<!DOCTYPE html><html><head><style>table {font-family: arial, sans-serif;border-collapse: collapse;width: 100%;}td {border: 1px solid #c7c7c7;text-align: left;padding: 8px;width: 30%;}th {border: 1px solid #c7c7c7;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #f2f2f2;}tr:hover {background-color: #dddddd;}tr:nth-child(even) {background-color: #dddddd;}</style></head><body><h2>Tabel Sistem Penanggalan</h2><table style="width:500px"><tr><th style="width:50%">Tahun</th><td id="datetime-year"></td></tr><tr><th style="width:50%">Bulan</th><td id="datetime-month"></td></tr><tr><th style="width:50%">Tanggal</th><td id="datetime-date"></td></tr><tr><th style="width:50%">Hari</th><td id="datetime-day"></td></tr><tr><th style="width:50%">Hari ke (dalam Setahun)</th><td id="datetime-dayinyear"></td></tr><tr><th style="width:50%">Jam</th><td id="datetime-hour"></td></tr><tr><th style="width:50%">Menit</th><td id="datetime-minute"></td></tr><tr><th style="width:50%">Detik</th><td id="datetime-second"></td></tr></table><br></br><h2>Info Tanggal</h2><table style="width:500px"><tr><th style="width:40%">Hari dan Tanggal</th><td id="datetime-daydate"></td></tr><tr><th style="width:40%">Waktu</th><td id="datetime-time"></td></tr><tr><th style="width:40%">Hari ke</th><td id="datetime-dayinyear2"></td></tr></table><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0" + jam).slice(-2) + ":" + ("0" + menit).slice(-2) + ":" + ("0" + detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.getElementById("datetime-daydate").innerHTML = hari+", "+tanggal+" "+bul+" "+tahun;document.getElementById("datetime-time").innerHTML = waktu;document.getElementById("datetime-year").innerHTML = tahun;document.getElementById("datetime-month").innerHTML = bul;document.getElementById("datetime-date").innerHTML = tanggal;document.getElementById("datetime-day").innerHTML = hari;document.getElementById("datetime-dayinyear").innerHTML = harke;document.getElementById("datetime-dayinyear2").innerHTML = harke;document.getElementById("datetime-hour").innerHTML = jam;document.getElementById("datetime-minute").innerHTML = menit;document.getElementById("datetime-second").innerHTML = detik;</script></body></html>
Hasil Output :
b. Dengan Persentase Tahun
Lebar dengan menggunakan Persentase :
<!DOCTYPE html><html><head><style>table {font-family: arial, sans-serif;border-collapse: collapse;width: 100%;}td {border: 1px solid #c7c7c7;text-align: left;padding: 8px;width: 30%;}th {border: 1px solid #c7c7c7;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #f2f2f2;}tr:hover {background-color: #dddddd;}tr:nth-child(even) {background-color: #dddddd;}</style></head><body><h2>Tabel Sistem Penanggalan</h2><table style="width:35%"><tr><th style="width:50%">Tahun</th><td id="datetime-year"></td></tr><tr><th style="width:50%">Bulan</th><td id="datetime-month"></td></tr><tr><th style="width:50%">Tanggal</th><td id="datetime-date"></td></tr><tr><th style="width:50%">Hari</th><td id="datetime-day"></td></tr><tr><th style="width:50%">Hari ke (dalam Setahun)</th><td id="datetime-dayinyear"></td></tr><tr><th style="width:50%">Sisa Hari (Tahun depan)</th><td id="datetime-daycuntdwn"></td></tr><tr><th style="width:50%">Persentase dalam Setahun</th><td id="datetime-percentage"></td></tr><tr><th style="width:50%">Persentase Hitung Mundur</th><td id="datetime-ctdwnprtg"></td></tr><tr><th style="width:50%">Jam</th><td id="datetime-hour"></td></tr><tr><th style="width:50%">Menit</th><td id="datetime-minute"></td></tr><tr><th style="width:50%">Detik</th><td id="datetime-second"></td></tr></table><br></br><h2>Info Tanggal</h2><table style="width:40%"><tr><th style="width:40%">Hari dan Tanggal</th><td id="datetime-daydate"></td></tr><tr><th style="width:40%">Waktu</th><td id="datetime-time"></td></tr><tr><th style="width:40%">Hari dan Persentase dalam Setahun</th><td id="datetime-daynprtg"></td></tr></table><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0"+jam).slice(-2)+":"+("0"+menit).slice(-2)+":"+("0"+detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);if (tahun % 400 == 0){leap = 366;}else if (tahun % 100 == 0){leap = 365;}else if (tahun % 4 == 0){leap = 366;}else {leap = 365;}var persen = 100/leap*(harke-1+(jam/24)+(menit/1440)+(detik/86400));var harmun = 1+leap-harke;var permun = 100-persen;var num1 = persen;var num2 = permun;const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.getElementById("datetime-daydate").innerHTML = hari+", "+tanggal+" "+bul+" "+tahun;document.getElementById("datetime-time").innerHTML = waktu;document.getElementById("datetime-daynprtg").innerHTML = "Day-"+harke+" ("+num1.toFixed(4)+"%)";document.getElementById("datetime-year").innerHTML = tahun;document.getElementById("datetime-month").innerHTML = bul;document.getElementById("datetime-date").innerHTML = tanggal;document.getElementById("datetime-day").innerHTML = hari;document.getElementById("datetime-dayinyear").innerHTML = harke;document.getElementById("datetime-daycuntdwn").innerHTML = harmun;document.getElementById("datetime-percentage").innerHTML = num1.toFixed(6)+"% <br/>";document.getElementById("datetime-ctdwnprtg").innerHTML = num2.toFixed(6)+"% <br/>";document.getElementById("datetime-hour").innerHTML = jam;document.getElementById("datetime-minute").innerHTML = menit;document.getElementById("datetime-second").innerHTML = detik;</script></body></html>
Lebar dengan menggunakan Piksel (px) :
<!DOCTYPE html><html><head><style>table {font-family: arial, sans-serif;border-collapse: collapse;width: 100%;}td {border: 1px solid #c7c7c7;text-align: left;padding: 8px;width: 30%;}th {border: 1px solid #c7c7c7;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #f2f2f2;}tr:hover {background-color: #dddddd;}tr:nth-child(even) {background-color: #dddddd;}</style></head><body><h2>Tabel Sistem Penanggalan</h2><table style="width:500px"><tr><th style="width:50%">Tahun</th><td id="datetime-year"></td></tr><tr><th style="width:50%">Bulan</th><td id="datetime-month"></td></tr><tr><th style="width:50%">Tanggal</th><td id="datetime-date"></td></tr><tr><th style="width:50%">Hari</th><td id="datetime-day"></td></tr><tr><th style="width:50%">Hari ke (dalam Setahun)</th><td id="datetime-dayinyear"></td></tr><tr><th style="width:50%">Sisa Hari (Tahun depan)</th><td id="datetime-daycuntdwn"></td></tr><tr><th style="width:50%">Persentase dalam Setahun</th><td id="datetime-percentage"></td></tr><tr><th style="width:50%">Persentase Hitung Mundur</th><td id="datetime-ctdwnprtg"></td></tr><tr><th style="width:50%">Jam</th><td id="datetime-hour"></td></tr><tr><th style="width:50%">Menit</th><td id="datetime-minute"></td></tr><tr><th style="width:50%">Detik</th><td id="datetime-second"></td></tr></table><br></br><h2>Info Tanggal</h2><table style="width:550px"><tr><th style="width:40%">Hari dan Tanggal</th><td id="datetime-daydate"></td></tr><tr><th style="width:40%">Waktu</th><td id="datetime-time"></td></tr><tr><th style="width:40%">Hari dan Persentase dalam Setahun</th><td id="datetime-daynprtg"></td></tr></table><script>const dt = new Date();let tahun = dt.getFullYear();let bulan = dt.getMonth()+1;let tanggal = dt.getDate();let har = dt.getDay();let jam = dt.getHours();let menit = dt.getMinutes();let detik = dt.getSeconds();let waktu = ("0"+jam).slice(-2)+":"+("0"+menit).slice(-2)+":"+("0"+detik).slice(-2);var start = new Date(tahun, 0, 0);var diff = (dt-start)+((start.getTimezoneOffset()-dt.getTimezoneOffset())*60*1000);var oneDay = 1000*60*60*24;var harke = Math.floor(diff/oneDay);if (tahun % 400 == 0){leap = 366;}else if (tahun % 100 == 0){leap = 365;}else if (tahun % 4 == 0){leap = 366;}else {leap = 365;}var persen = 100/leap*(harke-1+(jam/24)+(menit/1440)+(detik/86400));var harmun = 1+leap-harke;var permun = 100-persen;var num1 = persen;var num2 = permun;const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];let bul = month[bulan-1];const weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];let hari = weekday[har];if (hari == "Sunday"){har = 7;}document.getElementById("datetime-daydate").innerHTML = hari+", "+tanggal+" "+bul+" "+tahun;document.getElementById("datetime-time").innerHTML = waktu;document.getElementById("datetime-daynprtg").innerHTML = "Day-"+harke+" ("+num1.toFixed(4)+"%)";document.getElementById("datetime-year").innerHTML = tahun;document.getElementById("datetime-month").innerHTML = bul;document.getElementById("datetime-date").innerHTML = tanggal;document.getElementById("datetime-day").innerHTML = hari;document.getElementById("datetime-dayinyear").innerHTML = harke;document.getElementById("datetime-daycuntdwn").innerHTML = harmun;document.getElementById("datetime-percentage").innerHTML = num1.toFixed(6)+"% <br/>";document.getElementById("datetime-ctdwnprtg").innerHTML = num2.toFixed(6)+"% <br/>";document.getElementById("datetime-hour").innerHTML = jam;document.getElementById("datetime-minute").innerHTML = menit;document.getElementById("datetime-second").innerHTML = detik;</script></body></html>
Hasil Output :
c. Dengan Persentase menggunakan Progress Bar
Lebar dengan menggunakan Persentase :
Lebar dengan menggunakan Piksel (px) :
Hasil Output :
15. HTML, CSS, PHP, dan JavaScript
a. Tanpa Persentase Tahun
b. Dengan Persentase Tahun
16. TypeScript
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di TypeScript :
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di TypeScript (Dengan Persentase Tahun) :
17. Go(lang)
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di Golang :
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di Golang (Dengan Persentase Tahun) :
18. Kotlin
a. Tanpa Persentase Tahun
Program Tanggal dan Waktu di Kotlin :
b. Dengan Persentase Tahun
Program Tanggal dan Waktu di Kotlin (Dengan Persentase Tahun) :
Mohon maaf apabila ada kesalahan dalam penulisan Kode apapun.
Terima Kasih 😄😘👌👍 :)