Friday, July 31, 2020

JAVA Code to get Date with Month and Time



                                GregorianCalendar  gc=new GregorianCalendar();
    gc.setTimeInMillis(System.currentTimeMillis());

    int day=gc.get(Calendar.DAY_OF_MONTH);
    int month=gc.get(Calendar.MONTH)+1;
    int year=gc.get(Calendar.YEAR);
    int hour = gc.get(Calendar.HOUR_OF_DAY);
                                int minute = gc.get(Calendar.MINUTE);
                         
    String date="Date: "+day+"/"+month+"/"+year+" Time : "+hour+":"+minute;
                               
                                System.out.print(date);

No comments:

Post a Comment