Best time for Tahajjud
It is best to delay this prayer to the last third portion of the night. Abu Hurairah quoted that the Messenger of Allah, as saying: "Our Lord descends to the lowest heaven during the last third of the night, inquiring: 'Who will call on Me so that I may respond to him? Who is asking something of Me so I may give it to him? Who is asking for My forgiveness so I may forgive him?"
`Amr ibn Abasah reported that he heard the Prophet (peace and blessings be upon him) saying: "The closest that a slave comes to his Lord is during the middle of the latter portion of the night. If you can be among those who remember Allah, the Exalted One, at that time then do so."
(Source: http://www.zaharuddin.net/index.php?option=com_content&task=view&id=247&Itemid=90)
package oop;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
*
* @author KN
*/
public class calTimesFinal {
private String maghrib;
private String subuh;
public calTimesFinal(String maghrib, String subuh){
this.maghrib = maghrib;
this.subuh = subuh;
}
public long calTimesDiff() throws ParseException{
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date1 = format.parse(maghrib);
Date date2 = format.parse(subuh);
long diff = date2.getTime() - date1.getTime();
return diff;
}
public String getMaghrib(){
return maghrib;
}
public String getSubuh(){
return subuh;
}
public String generateTimesPeriod(int miliSeconds){
long seconds = miliSeconds / 1000 % 60;
long minutes = miliSeconds / (60 * 1000) % 60;
long hours = miliSeconds / (60 * 60 * 1000) % 24;
return hours+" jam, "+minutes+" minit, "+seconds+", saat";
}
public String generateClockFormat(int miliSeconds){
long seconds = miliSeconds / 1000 % 60;
long minutes = miliSeconds / (60 * 1000) % 60;
long hours = miliSeconds / (60 * 60 * 1000) % 24;
return hours+":"+minutes+":"+seconds;
}
public static void main(String[] args) throws ParseException{
Scanner cin = new Scanner(System.in);
System.out.print("Masukan waktu Maghrib "
+ "\ncth: 05/22/2017 19:00:00)"
+ "\n=> ");
String maghrib = cin.nextLine();
System.out.print("\nMasukan waktu Subuh "
+ "\ncth: 05/23/2017 19:00:00)"
+ "\n=> ");
String subuh = cin.nextLine();
calTimesFinal obj = new calTimesFinal(maghrib, subuh);
System.out.println("---------------------------------------------------------------------");
System.out.println("PENGIRAAN WAKTU TERBAIK SOLAT TAHAJJUD");
System.out.println("---------------------------------------------------------------------");
System.out.print("Maghrib = "+obj.getMaghrib());
System.out.println(", Subuh = "+obj.getSubuh());
System.out.println("---------------------------------------------------------------------");
System.out.println("Beza waktu Maghrib dan Subuh\t= "+obj.calTimesDiff()+"(milisaat)");
int maghribSubuh = (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())));
System.out.println(obj.generateTimesPeriod(maghribSubuh));
System.out.println("---------------------------------------------------------------------");
int sePertigaMalam = (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())) * 0.33333333);
System.out.println("A. Sepertiga malam\t\t= "+sePertigaMalam+"(milisaat)\n");
System.out.print(obj.generateTimesPeriod(sePertigaMalam)+ " dari ");
int jam = Integer.parseInt(obj.getMaghrib().substring(11,13));
int minit = Integer.parseInt(obj.getMaghrib().substring(14,16));
int saat = Integer.parseInt(obj.getMaghrib().substring(17,19));
System.out.println(jam+":"+minit+":"+saat+" (Maghrib)");
int jumSaat = (((jam*60*60) + (minit*60) + saat)*1000) + sePertigaMalam;
System.out.println(obj.generateClockFormat(jumSaat)+" (Jam terakhir 1/3 malam)");
System.out.println("---------------------------------------------------------------------");
int duaPertigaMalam = (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())) * 0.33333333)
+ (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())) * 0.33333333);
System.out.println("B. Dua pertiga malam\t\t= "+duaPertigaMalam+"(milisaat)\n");
System.out.print(obj.generateTimesPeriod(duaPertigaMalam)+ " dari ");
int jam2 = Integer.parseInt(obj.getMaghrib().substring(11,13));
int minit2 = Integer.parseInt(obj.getMaghrib().substring(14,16));
int saat2 = Integer.parseInt(obj.getMaghrib().substring(17,19));
System.out.println(jam2+":"+minit2+":"+saat2+" (Maghrib)");
int jumSaat2 = (((jam2*60*60) + (minit2*60) + saat2)*1000) + duaPertigaMalam;
System.out.println(obj.generateClockFormat(jumSaat2)+" (Jam terakhir 2/3 malam)");
System.out.println("---------------------------------------------------------------------");
System.out.println("C.Bahagian ketiga terakhir malam\n");
int tigaPertigaMalam = (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())) * 0.33333333)
+ (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())) * 0.33333333)
+ (int) (Double.parseDouble(String.valueOf(obj.calTimesDiff())) * 0.33333333);
int jumSaat3 = (((jam2*60*60) + (minit2*60) + saat2)*1000) + tigaPertigaMalam;
int bahagianKetigaTerakhirMalam = jumSaat2 + (1 * 1000);
System.out.print("0"+obj.generateClockFormat(bahagianKetigaTerakhirMalam)+"(Mula)");
int bahagianTengahKetigaTerakhirMalam = jumSaat2 + (sePertigaMalam / 2) + (1 * 1000);
System.out.print(", 0"+obj.generateClockFormat(bahagianTengahKetigaTerakhirMalam)+"(Tengah)");
System.out.println(", "+obj.getSubuh()+"(Subuh)");
System.out.println("\ni - Abu Hurairah: "
+ "\nTahajjud = Bahagian ketiga terakhir malam"
+ "\n"+"0"+obj.generateClockFormat(bahagianKetigaTerakhirMalam)
+" - "+"0"+obj.generateClockFormat(jumSaat3));
System.out.println("\nii - Amr ibn Abasah: "
+ "\nTahajjud = Pada pertengahan bahagian akhir malam"
+ "\n"+"0"+obj.generateClockFormat(bahagianKetigaTerakhirMalam)
+" - "+"0"+obj.generateClockFormat(bahagianTengahKetigaTerakhirMalam));
System.out.println("\nSumber rujukan: "
+ "\nhttp://www.zaharuddin.net/index.php?option=com_content&task=view&id=247&Itemid=90"
+ "\nhttp://www.islamhelpline.net/node/7178");
System.out.println("---------------------------------------------------------------------");
}
}