本文整理汇总了Java中com.alibaba.fastjson.JSON.toJSONStringWithDateFormat方法的典型用法代码示例。如果您正苦于以下问题:Java JSON.toJSONStringWithDateFormat方法的具体用法?Java JSON.toJSONStringWithDateFormat怎么用?Java JSON.toJSONStringWithDateFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSON
的用法示例。
在下文中一共展示了JSON.toJSONStringWithDateFormat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_0
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_0() throws Exception {
Entity object = new Entity();
object.setValue(new Date());
String text = JSON.toJSONStringWithDateFormat(object, "yyyy");
SimpleDateFormat format = new SimpleDateFormat("yyyy", JSON.defaultLocale);
format.setTimeZone(JSON.defaultTimeZone);
Assert.assertEquals("{\"value\":\"" + format.format(object.getValue()) + "\"}",
text);
}
示例2: toJson
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
@Override
public String toJson(Object object, boolean pretty) {
String dp = datePattern == null ? defaultDatePattern : datePattern;
if (pretty) {
return JSON.toJSONStringWithDateFormat(object, dp, prettyFeatures);
}
return JSON.toJSONStringWithDateFormat(object, dp, defaultFeatures);
}
示例3: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
TestBean test = new TestBean();
String stime2 = "2017-09-22 15:08:56";
LocalDateTime time1 = LocalDateTime.now();
time1 = time1.minusNanos(10L);
System.out.println(time1.getNano());
LocalDateTime time2 = LocalDateTime.parse(stime2, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.CHINA));
test.setTime1(time1);
test.setTime2(time2);
String t1 = JSON.toJSONString(time1, SerializerFeature.WriteDateUseDateFormat);
String json = JSON.toJSONString(test, SerializerFeature.WriteDateUseDateFormat);
Assert.assertEquals("{\"time1\":"+t1+",\"time2\":\""+stime2+"\"}",json);
//String default_format = JSON.DEFFAULT_LOCAL_DATE_TIME_FORMAT;
//JSON.DEFFAULT_LOCAL_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
//String stime1 = DateTimeFormatter.ofPattern(JSON.DEFFAULT_LOCAL_DATE_TIME_FORMAT, Locale.CHINA).format(time1);
json = JSON.toJSONString(test, SerializerFeature.WriteDateUseDateFormat);
Assert.assertEquals("{\"time1\":"+ JSON.toJSONString(time1, SerializerFeature.WriteDateUseDateFormat) +",\"time2\":\""+stime2+"\"}",json);
String pattern = "yyyy-MM-dd HH:mm:ss";
String stime1 = DateTimeFormatter.ofPattern(pattern, Locale.CHINA).format(time1);
json = JSON.toJSONStringWithDateFormat(test, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat);
Assert.assertEquals("{\"time1\":\""+stime1+"\",\"time2\":\""+stime2+"\"}",json);
//JSON.DEFFAULT_LOCAL_DATE_TIME_FORMAT = default_format;
}
示例4: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
LocalDateTime localDateTime = LocalDateTime.of(2018, 8, 31, 15, 26, 37, 1);
String json = JSON.toJSONStringWithDateFormat(localDateTime, "yyyy-MM-dd HH:mm:ss");//2018-08-31T15:26:37.000000001
assertEquals("\"2018-08-31 15:26:37\"", json);
}
示例5: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
java.util.Date date = JSON.parseObject("\"2017-3-17 00:00:01\"", java.util.Date.class);
String json = JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd");
assertEquals("\"2017-03-17\"", json);
}
示例6: test_for_issue_2
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue_2() throws Exception {
java.util.Date date = JSON.parseObject("\"2017-3-7 00:00:01\"", java.util.Date.class);
String json = JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd");
assertEquals("\"2017-03-07\"", json);
}
示例7: jsonizeNodeInfo
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
private String jsonizeNodeInfo(NodeInfo nodeInfo) {
String dateFormat = "yyyy-MM-dd HH:mm:ss";
return JSON.toJSONStringWithDateFormat(nodeInfo, dateFormat, SerializerFeature.WriteDateUseDateFormat);
}
示例8: toPrettyJson
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public static String toPrettyJson(Object obj) {
return JSON.toJSONStringWithDateFormat(obj, DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(),
SerializerFeature.PrettyFormat);
}
示例9: test_for_issue
import com.alibaba.fastjson.JSON; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
final String pattern = "yyyy-MM-dd HH:mm:ss";
LocalDateTime dateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
String text = JSON.toJSONStringWithDateFormat(dateTime, pattern);
assertEquals(JSON.toJSONString(formatter.format(dateTime)), text);
}