Android: Get the day of the week from a date?

How can I format the date this way

Mon, Nov 27, 2011

public static String sFleTimeToDate(double ft) { double date = ft / 10000 - 11644455600000L; date += TimeZone.getDefault().getOffset((long) date); return DateFormat.format("ddd, dd MMM yyyy", new Date((long) date)).toString(); } 

but this function returns

027, November 27, 2011

+6
source share
4 answers

You can change your DateFormat.format format to

  DateFormat.format("EEE, dd MMM yyyy", new Date((long) date)).toString(); 
+9
source

To get day after week you must use EEE

 SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy); 

You can create any format you want, just take a look at this tutorial.

+4
source

look at the link. It shows various format options.

I updated your method, try now,

 public static String sFleTimeToDate(double ft) { double date = ft / 10000 - 11644455600000L; date += TimeZone.getDefault().getOffset((long) date); return DateFormat.format("E, dd MMM yyyy", new Date((long) date)).toString(); } 
+1
source

Get current date With expected format:

 String currentDateTimeString =DateFormat.getDateInstance().format(new Date()); txtToday.setText(currentDateTimeString); 
-1
source

Source: https://habr.com/ru/post/906758/


All Articles