1

I want show date into my application, and i receive this data from server with below json :

"date": "2016-08-01 19:55:16"

and i set into textview with below code :

((DataViewHolder) holder).main_dateTime.setText(Html.fromHtml(mDateSet.get(position).getDate()));

I want convert this date to jalali/shamsi . but i don't know how to convert this date and set into textview !

Can you help me for this issue?

  • 1
    if you want to convert the date to **jalali/shamsi** here is method to convert http://stackoverflow.com/questions/10378764/is-there-any-library-or-algorithm-for-persian-shamsi-or-jalali-calendar-in-and and this library https://github.com/amirmehdizadeh/JalaliCalendar if still there is problem kindly comment – Fahad Rehman Sep 04 '16 at 13:27
  • @FahadRehman, thank you. I copy class in my project, but how can I use this into `((DataViewHolder) holder).main_dateTime.setText(Html.fromHtml(mDateSet.get(position).getDate()));` ? please help me, I am amateur and I really need this –  Sep 04 '16 at 13:32
  • ok i havent tried this library let me try it and i will answer you in few minutes – Fahad Rehman Sep 04 '16 at 13:36
  • @FahadRehman, thanks I am waiting –  Sep 04 '16 at 13:37
  • @FahadRehman, can you help me my friend? –  Sep 04 '16 at 14:16
  • I have added the answer if you have any problems let me know, i don't have any idea about Jalali calendar so i cant tell you accuracy about the library – Fahad Rehman Sep 04 '16 at 14:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122619/discussion-between-fahad-rehman-and-user6761472). – Fahad Rehman Sep 04 '16 at 14:55

1 Answers1

3

Use this https://github.com/amirmehdizadeh/JalaliCalendar to get the Jalali date

first get the year, month and day from your date like

String date = "2016-08-01 19:55:16";

String[] parts = date.split(" ");
String datePart = parts[0];
String timePart = parts[1];

int year;
int month;
int day;

String[] dateParts = datePart.split("-");
year = Integer.parseInt( dateParts[0]);
month = Integer.parseInt( dateParts[1]);
day = Integer.parseInt( dateParts[2]);

then create the Object to pass to that library

JalaliCalendar.YearMonthDate  georgianDate = new JalaliCalendar.YearMonthDate(year,month,day);

and then call its method that convert from Georgian date to Jalali Date

 JalaliCalendar.YearMonthDate JalaliDate = JalaliCalendar.gregorianToJalali(georgianDate);

And Finally append the date with time to show in text view

String jalaliDateTime =  JalaliDate.toString() + " " + timePart;
textView.setText(jalaliDateTime);
Fahad Rehman
  • 1,189
  • 11
  • 25