Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json4excel 时间格式转换问题 #100

Open
Rekoe opened this issue May 9, 2018 · 4 comments
Open

json4excel 时间格式转换问题 #100

Rekoe opened this issue May 9, 2018 · 4 comments
Labels

Comments

@Rekoe
Copy link
Member

Rekoe commented May 9, 2018

@pangwu86
Flash_Sale.xlsx
文件里面的 开始时间 和结束时间 两列配置的整点时间 转换后出现了2018-05-09 09:59:59 但里面配置的都是整点的数据

@J4EName("flash_sale")
public class FlashSale {

	@J4EName("开始时间")
	private String from;

	@J4EName("结束时间")
	private String to;

	@J4EName("商品ID")
	private long itemId;

	@J4EName("skuID")
	private long skuId;

	@J4EName("闪购价")
	@J4EDefine(precision = 2)
	private float price;

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}

	public long getItemId() {
		return itemId;
	}

	public void setItemId(long itemId) {
		this.itemId = itemId;
	}

	public long getSkuId() {
		return skuId;
	}

	public void setSkuId(long skuId) {
		this.skuId = skuId;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

}

code

File outFile = Files.createFileIfNoExists2(Disks.normalize("Flash_Sale.xlsx"));
		List<FlashSale> list = J4E.fromExcel(Streams.fileIn(outFile), FlashSale.class, null);
		for (FlashSale flashSale : list) {
			String fromStr = flashSale.getFrom();
			Date from = SaudiTime(fromStr);
			String toStr = flashSale.getTo();
			System.out.println(fromStr + " ," + toStr );
                }
}
@pangwu86
Copy link
Member

pangwu86 commented May 9, 2018

嗯,下午me查查

@Rekoe
Copy link
Member Author

Rekoe commented May 9, 2018

@pangwu86
搞出来了没 ?

@pangwu86
Copy link
Member

pangwu86 commented May 9, 2018

excel里实际存储的是日期类型 ,poi接口拿到的就是你最终看到的有整点有59的,看了下poi的实现,里面实际存储的是个double类型 然后转成日期,但为什么字面上一样的日期读取来的double不一样 这个还在查

@pangwu86
Copy link
Member

pangwu86 commented May 9, 2018

@Rekoe 目前看这个应该是POI的bug,excel存储时那个字段设置成日期类型 在poi里就只能以double类型读取到 poi读出来的就是差1s也是无法让人理解

me推荐你如果这个读取的excel是你能控制的,那就是保存日期时用字符串类型

@pangwu86 pangwu86 added the bug label May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants