当前位置: 首页>>代码示例>>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;未经允许,请勿转载。