These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

getmonth() format

bigfatnoob
Registered: Mar 16 2008
Posts: 12

I am currently using this JavaScript function (1 + CurrDate.getMonth()) to get the current month. It works fine, but i would like to know if it is possible to change the format of the output.

The current output for April = 4
and I would like to have the format of April = 04
ie ( YYYY-MM-DD)

i am fairly new to javascript, so would you please be very kind to direct me in the right direction if it is at all possible.

many thanks.

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
You have a choice of methods

1. Use the "util.printd()" method to specidfy the entire formatted string.

util.printd("yyyy-MM-dd", CurrDate)

2. Use the "util.printf()" method to add the leading zero to the month.

util.printf("%,102d", (CurrDate.getMonth() + 1))

3. Add a leading character zero to the result of the calcualtion and substring the last 2 characters of the string.

var CurrMonth = "0" + (CurrDate.getMonth() + 1);
CurrMonth.substr(CurrMonth.length - 2, 2)

George Kaiser

bigfatnoob
Registered: Mar 16 2008
Posts: 12
thanks for the help~!

i have experimented abit with the 3 functions, and i can only get the 3rd to work.

and i end up with the following codes in the "docReady" event:
var CurrDate = new Date(); var NowYear = CurrDate.getFullYear(); var NowMonth = "0" + (CurrDate.getMonth() + 1);NowMonth.substr(NowMonth.length - 2, 2); var NowDate = CurrDate.getDate(); this.rawValue = NowYear + "-" +  NowMonth + "-" + NowDate;

however for some reason i can't get the util.print function to work. Is it that it is not possible to use it on "docReady"??
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Apparently liveCycle Designer does not support the "util" object and it's methods.

George Kaiser

bigfatnoob
Registered: Mar 16 2008
Posts: 12
oh... I see.

Just one more question, I was wondering if it is possible to update the date field on save?
bigfatnoob
Registered: Mar 16 2008
Posts: 12
sorry for the lack of information above, i have tried the above function with the PreSave event, and it does not return any value on save.
Lindy
Registered: Jul 17 2007
Posts: 30
This should give you the result you seek - LiveCycle will support util. The Case of the arguments is significant. Cap the Y's & D's or it will bomb on 'invalid arguments'. The Javascript Scripting Reference does not have this correct.this.rawValue = (util.printd("YYYY-MM-DD", new Date(), true));
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Since LiveCycle Designer use the XFA format, one has to set the "bXFAPicture" to true and use the XFA picture format and not the Acrobat AcroForms picture format. The documentation for version 7 has a discussion of this parameter, references to web documentation, and examples showing the difference between the 2 different picture formats which goes beyond just the use capital letters.

George Kaiser