将Java Date转换为dbf FoxPro datetime格式 [英] Convert java Date to dbf FoxPro datetime format

查看:134
本文介绍了将Java Date转换为dbf FoxPro datetime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在FoxPro规范中创建DBF文件,但是idk如何插入日期.我不知道如何将Java Date转换为此:

Im trying to create DBF file in FoxPro spec, but idk how to insert date. I dont know how to convert java Date to this:

FoxPro的字段是2个32位整数:一个存储日期,另一个存储日期 存储时间,以反向字节顺序存储.日期整数存储 从1/1/4712BC开始的天数.时间整数存储数字 从00:00:00开始的毫秒数.

FoxPro's field is 2 32bit integers: one stores the date, the other stores the time, stored in reverse byte order. The date integer stores the number of days from 1/1/4712BC. The time integer stores the number of milliseconds from 00:00:00.

使用JodaTime轻松获得天数和毫秒数:

Its easy to get days and milliseconds with JodaTime:

         DateTime start = new DateTime(-4713, 1, 1, 0, 0, 0, 0);
         DateTime end = new DateTime(2014, 1, 1, 0, 0, 0, 0);
         Days days = Days.daysBetween(start, end);
         long millis = end.getMillisOfDay();

但是如何将此信息转换为所需的格式? 要输入日期,我只使用:

but how to convert this info to needed format? For input a date I just use:

SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMdd");
simpledateformat.format(date);

及其工作正常,但是当我尝试将日期时间与"yyyyMMddHHmmss"一起使用时,我看到非常糟糕的结果,例如17.08.33409 12:34:20(仅月份正确).

and its work fine, but when I try use datetime with "yyyyMMddHHmmss" I see very bad result, like 17.08.33409 12:34:20 (only month is correct).

推荐答案

VFP同时具有Date和DateTime字段类型.

VFP has both Date and DateTime field types.

用于插入日期的VFP语法为:

The VFP syntax for inserting a date is:

Insert into mytable (mydatefield) values ({^YYYY-MM-DD})

Insert into mytable (mydatefield) values (Date(YYYY,MM,DD))

对于日期时间(假设VFP中的字段为日期时间)

And for a datetime (assuming the field in VFP is a datetime)

Insert into mytable (mydatefield) values ({^YYYY-MM-DD HH:MM:SS})

Insert into mytable (mydatefield) values (DateTime(YYYY,MM,DD,HH,MM,SS)) 

因此,假设您可以从Java日期中提取年,月和日的文本表示形式,则可以从中建立VFP查询.

So assuming you can extract a text representation of the year, month and day from your Java date you can build up your VFP query from that.

这篇关于将Java Date转换为dbf FoxPro datetime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆