问题
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'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.
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);
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).
回答1:
VFP has both Date and DateTime field types.
The VFP syntax for inserting a date is:
Insert into mytable (mydatefield) values ({^YYYY-MM-DD})
or
Insert into mytable (mydatefield) values (Date(YYYY,MM,DD))
And for a datetime (assuming the field in VFP is a datetime)
Insert into mytable (mydatefield) values ({^YYYY-MM-DD HH:MM:SS})
or
Insert into mytable (mydatefield) values (DateTime(YYYY,MM,DD,HH,MM,SS))
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.
来源:https://stackoverflow.com/questions/25506256/convert-java-date-to-dbf-foxpro-datetime-format