Skip to content

Instantly share code, notes, and snippets.

@bmnepali
Last active March 19, 2020 12:01
Show Gist options
  • Save bmnepali/dda28c1c4844a6598632e86f8fd66386 to your computer and use it in GitHub Desktop.
Save bmnepali/dda28c1c4844a6598632e86f8fd66386 to your computer and use it in GitHub Desktop.
Get full fay name from given date
public class GetDayFromDate {
public static void main(String[] args) {
Date now = new Date();
SimpleDateFormat simpleDateformat = new SimpleDateFormat("E"); // the day of the week abbreviated
System.out.println(simpleDateformat.format(now));
simpleDateformat = new SimpleDateFormat("EEEE"); // the day of the week spelled out completely
System.out.println(simpleDateformat.format(now));
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);
System.out.println(calendar.get(Calendar.DAY_OF_WEEK)); // the day of the week in numerical format
}
}
// Output
// Wed
// Wednesday
// 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment