-2

I have this:

integeres = "1495022669";

I want the output:

"May 17"

How can I achieve it? I tried several answers on internet but couldn't get success.

Edited

i tried this code

level = 1495023057;

DateTimeZone timeZone = DateTimeZone.forID( "Asia/Karachi" );
                            DateTime dateTime = new DateTime( level, timeZone );
                            int dayOfWeekNumber = dateTime.getDayOfWeek(); // ISO 8601 standard says Monday is 1.
                            DateTimeFormatter formatter = DateTimeFormat.forPattern( "EEEE" ).withLocale( java.util.Locale.ENGLISH );
                            String dayOfWeekName = formatter.print( dateTime );

it gives me sunday .... but in my timezone it is wednesday. so i am stuck here , its i think joda time library that is why i am having wrong day name.

kindly help with suiteable answers.

Edited 2

solution

String dateAsText = new SimpleDateFormat("EEEE, dd MMMM")
                                    .format(new Date(level * 1000L));
Addi.Star
  • 475
  • 2
  • 15
  • 36
  • 1
    http://stackoverflow.com/a/17433005/6756514 – Divyesh Patel May 17 '17 at 12:10
  • 1
    Or http://stackoverflow.com/questions/10477714/converting-integer-time-stamp-into-java-date – Denny May 17 '17 at 12:12
  • You say you have tried several things so you should post that code here and explain specifically what did not work about each one. Then you might be able to ask a question which is not just asking us to write code for you. – takendarkk May 17 '17 at 12:13
  • where and how'd you get your integer value? Is it valid integer/long value? Generally integer/long values tells time in millis? – Haris Qurashi May 17 '17 at 13:31
  • Getting it from server api – Addi.Star May 17 '17 at 13:44
  • 1
    Possible duplicate of [Unix epoch time to Java Date object](http://stackoverflow.com/questions/535004/unix-epoch-time-to-java-date-object). And/or of [Convert unix time to week day](http://stackoverflow.com/questions/43676183/convert-unix-time-to-week-day). – Ole V.V. May 17 '17 at 14:15

2 Answers2

0

My suggestion is

    ZoneId timeZone = ZoneId.of("Asia/Karachi");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE, dd MMMM", Locale.ENGLISH);
    String dateAsText = Instant.ofEpochSecond(Long.parseLong(integeres))
            .atZone(timeZone)
            .format(formatter);

This produces

Wednesday, 17 May

I understand that you are using Joda-Time in the question, and if you are happy with that, you may not want to change. For new code I recommend JSR-310, so this is what I am using above. The Joda-Time homepage says “Users are now asked to migrate to java.time (JSR-310).” For Android this means ThreeTenABP.

You may also want to start your transistion to JSR-310 now; I am told that Joda-Time and ThreeTenABP can coexist happily. You need to watch your imports, though, since some of the classes have the same name in both libraries.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
-1

Below code will provide your desired output

import android.text.format.DateUtils;

public String getDate(long timestamp) {
        long Yesterday = new Date().getTime() - 24 * 60 * 60 * 1000;
        timestamp = timestamp * 1000;
        if (DateUtils.isToday(timestamp)) {
            return "Today";
        } else if (DateUtils.formatDateTime(MainActivity.this, Yesterday, DateUtils.FORMAT_SHOW_YEAR).equalsIgnoreCase(DateUtils.formatDateTime(MainActivity.this, timestamp, DateUtils.FORMAT_SHOW_YEAR))) {
            return "Yesterday";
        } else {
            return DateUtils.formatDateTime(ChattingScreenActivity.this, timestamp, DateUtils.FORMAT_SHOW_YEAR);
        }
}

Edited 2

I solved it by using this :

String dateAsText = new SimpleDateFormat("EEEE, dd MMMM")
                                    .format(new Date(level * 1000L));
Addi.Star
  • 475
  • 2
  • 15
  • 36
ashish
  • 848
  • 6
  • 16
  • If you are over smart than keep quit understand. Just do your work no need your answer . If you not able to help some one atlist do not -1 answer. – ashish May 17 '17 at 12:16