Skip to content

Instantly share code, notes, and snippets.

@na5imuzzaman
Created September 21, 2017 08:30
Show Gist options
  • Save na5imuzzaman/440e160df06a2c6f4cf18d2891f65e43 to your computer and use it in GitHub Desktop.
Save na5imuzzaman/440e160df06a2c6f4cf18d2891f65e43 to your computer and use it in GitHub Desktop.
Current Time Code in JAVA
/*
@author Nasimuzzaman Nasim
*/
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Main
{
public static void main(String args[])
{
DecimalFormat df1 = new DecimalFormat("00");
long miliS = System.currentTimeMillis();
long sec = miliS/1000;
int currSec = (int) sec%60;
long min = sec/60;
int currMin = (int) min%60;
long hour = min/60;
int currHour = (int) (hour-1)%24;
String time;
if (currHour>12)
{
currHour = currHour%12;
time = "PM";
}
else
time = "AM";
JOptionPane.showMessageDialog(null,df1.format (currHour) + " : "
+ df1.format(currMin) + " : " + df1.format(currSec) + " " + time,
"Current BD Time",JOptionPane.INFORMATION_MESSAGE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment