我有一个文本字段,它以mmmm,yyyy (称为“过期日期”)为单位显示日期,我正在尝试创建三个较小的字段,在每个字段中只显示日( d )、月(m)和年(yyyy)。
我尝试使用以下代码将数据导入到每个字段中:
var sField = 'Expiry Date'然后我会根据需要将其自定义格式化为"d“、"m”或"yyyy“。在小的格式化预览窗口中,它将显示所需的输出,但字段仍为空白。
同样奇怪的是,它只适用于以月份开头的格式。
我得到的第一个日期的字段是从另一个计算中创建的,如果这使它有所不同的话。“过期日期”从名为“日期”的字段中获取数据。下面的代码中,它在' date‘的值之后30天分配一个过期日期
// define the value for the date field
var sField = 'Date'
// define the format of the date string
var cFormatDate = 'mm/dd/yyyy';
// define some time constants
var fSecond = 1000; // number of milliseconds in one second
var fMinute = 60 * fSecond; // number of milliseconds in a minute
var fHour = 60 * fMinute; // number of milliseconds in an hour
var fDay = 24 * fHour; //number of milliseconds in a day
// get the field object's string value
var fTodayDate = this.getField(sField).value;
// convert the string value into a date object
var oDate = util.scand(cFormatDate, fTodayDate);
// convert the date object to a value in milliseconds
var fDate = oDate.getTime();
// add 30 days to value using the number of milliseconds in a day
var fNewDate = fDate + (30 * fDay);
// convert computed date value to date object
var oNewDate = new Date(fNewDate);
// set the field's value to the date string for the date object
event.value = util.printd(cFormatDate, oNewDate);提前感谢!!
发布于 2012-10-17 10:06:40
我对Acrobat一无所知,但假设它的Date对象符合ECMA-262。到目前为止,将日期字符串转换为date对象的最佳方法是自己解析它,而不是把它留给Date函数/构造函数或Date.parse。
从你的帖子看,日期字符串看起来像October 17, 2012。下面有一个函数可以帮助你做到这一点。
添加整天的最好方法是将它们添加到日期中,因此给定一个date对象:
// Create a new Date object
var now = new Date();
// Copy it
var then = new Date(now);
// Add 30 days
then.setDate(then.getDate() + 30);请注意,在1月28日(或闰年的1月29日)之后添加30个日期将在3月份结束。
编辑
日期字符串解析函数:
// Expects mmm d, yyyy e.g. October 17, 2012 or Oct 17, 2012
function parseDateString(s) {
var months={jan:0, feb:1, mar:2, apr:3, may:4, jun:5,
jul:6, aug:7, sep:8, oct:9, nov:10, dec:11};
var d = s.split(/\s/);
return new Date(d[2], months[d[0].toLowerCase().substring(0,3)], parseInt(d[1],10));
}发布于 2012-11-06 01:19:23
我可能过于简单了,但是如果您有一个日期字段(让我们将其命名为"DATE1"),其中包含完整的日期。
你就不能把这个字段复制三次,给这三个字段的名字都指定"DATE1“吗?这将采用您在原始日期字段中键入的日期,并在其他三个字段中复制该日期。然后进入字段属性,确保所有4个框的格式都是" Date“--然后在3个较小的框中,分别为它们分配"dd”、"mm“或"yy”的自定义日期选项?
https://stackoverflow.com/questions/12925166
复制相似问题