當前位置: 首頁>>代碼示例>>Java>>正文


Java JSON.toJSONStringWithDateFormat方法代碼示例

本文整理匯總了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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:DateFieldTest8.java

示例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);
}
 
開發者ID:Xlongshu,項目名稱:EasyController,代碼行數:9,代碼來源:FastJson.java

示例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;
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:34,代碼來源:Issue1493.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:Issue1450.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:Issue1080.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:Issue1080.java

示例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);
}
 
開發者ID:imadcn,項目名稱:idworker,代碼行數:5,代碼來源:ZookeeperWorkerRegister.java

示例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);
}
 
開發者ID:wangmeng1314,項目名稱:Code-warehouse,代碼行數:5,代碼來源:BaseTester.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:Issue942.java


注:本文中的com.alibaba.fastjson.JSON.toJSONStringWithDateFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。