如何将字符串时间戳从格里高利转换为shamsi

时间:2017-02-15 13:01:49

标签: android

你好我从gregorian的服务器获得一个时间戳看起来像这个

{
  "error": false,
  "users": [
    {
      "id": 1,
      "username": "dfsg",
      "active": 1,
      "created_at": "2017-02-14 00:13:25"
    },
    {
      "id": 2,
      "username": "asf",
      "active": 1,
      "created_at": "2017-02-14 13:42:26"
    },
    {
      "id": 3,
      "username": "test2",
      "active": 1,
      "created_at": "2017-02-15 13:57:31"
    }
  ]
}

我希望将它更改为shamsi应该是什么样子 1395-11-26 13:42:26 有没有上课呢?谢谢

2 个答案:

答案 0 :(得分:2)

您可以在项目中添加此类source

mov direct,%eax # move memory at direct to %eax

答案 1 :(得分:1)

使用Joda Time

因此:

        Chronology iso = ISOChronology.getInstanceUTC();
        Chronology hijri = IslamicChronology.getInstanceUTC();

        LocalDate todayIso = new LocalDate(2013, 3, 31, iso);
        LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(),
                                             hijri);
        System.out.println(todayHijri); // 1434-05-19

要从字符串中获取年,月和日,请使用以下内容:

String startDateString = "2017-02-14 00:13:25";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
Date date = df.parse(startDateString);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);

int year = calendar.get(Calendar.YEAR);
//Add one to month {0 - 11}
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);