- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好,我正在从服务器获取公历时间戳,看起来像这样
{
"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有什么课可以做吗?谢谢
最佳答案
你可以在你的项目中添加这个类,source
import java.text.SimpleDateFormat;
import java.util.Date;
public class PersianDate {
public String todayShamsi()
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String curentDateandTime = sdf.format(new Date());
String year = curentDateandTime.substring(0, 4);
String month = curentDateandTime.substring(4, 6);
String day = curentDateandTime.substring(6, 8);
int Y = Integer.valueOf(year);
int M = Integer.valueOf(month);
int D = Integer.valueOf(day);
return Shamsi(Y, M, D);
}
public static String Shamsi(int Y, int M, int D)
{
if (Y == 0)
Y = 2000;
if (Y < 100)
Y = Y + 1900;
if (Y == 2000)
{
if (M > 2)
{
SimpleDateFormat temp = new SimpleDateFormat("yyyyMMdd");
String curentDateandTime = temp.format(new Date());
String year = curentDateandTime.substring(0, 4);
String month = curentDateandTime.substring(4, 6);
String day = curentDateandTime.substring(6, 8);
Y = Integer.valueOf(year);
M = Integer.valueOf(month);
D = Integer.valueOf(day);
}
}
if (M < 3 || (M == 3 && D < 21))
{
Y -= 622;
}
else Y -= 621;
switch (M)
{
case 1: if (D < 21)
{
M = 10;
D = D + 10;
}
else
{
M = 11;
D -= 20;
}
break;
case 2: if (D < 20)
{
M = 11;
D = D + 11;
}
else
{
M = 12;
D -= 19;
}
break;
case 3:
if (D < 21)
{
M = 12;
D = D + 9;
}
else
{
M = 1;
D -= 20;
}
break;
case 4:
if (D < 21)
{
M = 1;
D = D + 11;
}
else
{
M = 2; D = D - 20;
}
break;
case 5:
if (D < 22)
{
M = M - 3;
D = D + 10;
}
else
{
M = M - 2;
D = D - 21;
}
break;
case 6:
if (D < 22)
{
M = M - 3;
D = D + 10;
}
else
{
M = M - 2;
D = D - 21;
}
break;
case 7:
if (D < 23)
{
M = M - 3;
D = D + 9;
}
else
{
M = M - 2;
D = D - 22;
}
break;
case 8:
if (D < 23)
{
M = M - 3;
D = D + 9;
}
else
{
M = M - 2;
D = D - 22;
}
break;
case 9:
if (D < 23)
{
M = M - 3;
D = D + 9;
}
else
{
M = M - 2;
D = D - 22;
}
break;
case 10:
if (D < 23)
{
M = 7;
D = D + 8;
}
else
{
M = 8;
D = D - 22;
}
break;
case 11:
if (D < 22)
{
M = M - 3;
D = D + 9;
}
else
{
M = M - 2;
D = D - 21;
}
break;
case 12:
if (D < 22)
{
M = M - 3;
D = D + 9;
}
else
{
M = M - 2;
D = D - 21;
}
break;
}
String month = "00";
String day = "00";
//D = Integer.valueOf(D)+1;
if (M < 10)
{
month = "0" + M;
}
else
{
month = String.valueOf(M);
}
if (D < 10)
{
day = "0" + D;
}
else
{
day = String.valueOf(D);
}
return String.valueOf(Y) + "/" + month + "/" + day;
}
}
关于android - 如何将字符串时间戳从公历转换为 shamsi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42250169/
我正在做一项作业,涉及使用 GregorianCalendar。规范说我需要使用 setLenient(false);我该怎么做呢?我还需要设置一个固定日期(2009 年 1 月 1 日),以便我的计
嘿伙计们,我知道这是一个非常简单的问题,但我是 Java 新手,所以请耐心等待。我创建了一个程序,可以计算一本书发行后返回的时间!所以请帮帮我。 这是我的代码: public void loan(
我在夏令时方面遇到了一个奇怪的问题。我有一个 java 程序计划在每天上午 00:05 运行,但昨天它在 23:05 运行。我正在使用公历在java中安排这个程序。在此之前,它从未在 23:05 运行
我在 Java 中使用 GregorianCalendar,我想知道如何使用它来检查日期是否有效(例如:检查 2 月 29 日是否仅在闰年, 检查日期是否不早于当前数据等)。 我已经创建了一个 Gre
我一直在试图弄清楚这个问题。这是关于JavaFX控件在按下回车键时选择月份、数字日和年的名称。我什至尝试使用面向对象来解决这个问题。问题在图片链接中。 Here is the question in
这个问题已经有答案了: Why is January month 0 in Java Calendar? (18 个回答) 已关闭 8 年前。 对于此代码,我必须做的就是使用 GregorianCal
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎偏离主题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或 include a mini
我创建了一个 TreeMap的 存储引入 GPS 闰秒的日期: leapSecondsDict = new TreeMap(); GregorianCalendar calendar = ne
在完成 JUnit 之后,我正在做一些基于文档的测试,在表格中包含以下项目 输入变量 - 预期结果 - 实际结果......通过或失败...... 如果我将日期和时间传递给我的方法 “01AUG07”
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Java Calendar Setting Incorrectly 我有这个代码: GregorianCalenda
我必须为我的 Java 类(class)制作一个功能齐全的日历,但我被卡住了。我正在使用 GregorianCalendar 来获取当前的日、月、年等。我正在使用 JButton 来填充填写日历的 4
我正在使用公历来设置日期值并尝试获取设置的值。代码如下 Constants.sSetDate_calendar = new GregorianCalendar(year,month,day);//
我有一个 9 月 2 日星期二的 GregorianCalendar 实例。 valñue 以毫秒为单位进行检查,没有问题。我想要下一个星期日(7 日)23:59:59 的另一个日历。所以: Greg
我有一个 JSP 页面,里面有一个 java 变量,其名称为 ${entry.date},该变量的类型为 Gregorian Calendar ,它放置在循环并最终生成错误日志表。现在我的问题是,在我
下面的程序是教程的一部分。我在这里有一些困惑包含以下几行: GregorianCalendar gCal = new GregorianCalendar();
我正在编写一个类来简化我可以使用 GregorianCalendar 进行的所有操作。我需要做的操作是:- 获取字符串格式的日期,翻译成意大利语;- 在两个日期之间进行减法。我没有使用过日历、日期和时
我是一个非常业余的编码员,他似乎无法解决从用户输入的整数中获取星期几(例如星期日、星期一等)的问题。我只是想给用户一条消息,其中列出了 (mm/dd/yyyy, dayOfWeek),但我没有改变星期
一些历法改革者寻求使一年中每个月的长度相等。这通常是通过创建一个日历来实现的,该日历有 13 个月,每个月有 4 周(28 天),共 364 天。已知最早的此类建议是格鲁吉亚日历 - more det
相同的代码 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:
我正在尝试将 pandas 数据帧转换为 SPSS 格式,但在转换 datetime64 变量时遇到问题。 使用以下代码: import pandas as pd import datetime as
我是一名优秀的程序员,十分优秀!