Discussion:
Netbeans templates - ${date}
Sal Stone
2008-07-30 15:17:22 UTC
Permalink
Hi,

I'm trying to change format of date/time in Java Class template...

from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"

In NetBeans 6.1 Tools/Templates Java Class gives me this:

/*
* ${name}.java
*
* Created on ${date}, ${time}
*/

...

When I create new class I get:
"Jul 30, 2008, 3:27:05 PM"

But if I create new JFrame I get this:
"July 30, 2008, 3:27 PM"

I see that "Java Class template" is using FreeMarker and "JFrame template "
not...

I looked in the manual

http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html


but I don't understand how this can be used inside Java Template...


Where does ${date} "variable" comes from, how can I change date_format or
is it possible to write some function to reformat date?

SS
Carl Swan
2008-07-30 15:38:28 UTC
Permalink
I had the same problem until I realized that the ${date} variable was of
type String not type Date. You have to cast it to a Date type then do the
format. I needed just the year so mine looked like this.

${date?date?string("yyyy")}

Hope that helps.

Carl
Post by Sal Stone
Hi,
I'm trying to change format of date/time in Java Class template...
from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"
/*
* ${name}.java
*
* Created on ${date}, ${time}
*/
...
"Jul 30, 2008, 3:27:05 PM"
"July 30, 2008, 3:27 PM"
I see that "Java Class template" is using FreeMarker and "JFrame template "
not...
I looked in the manual
http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html
but I don't understand how this can be used inside Java Template...
Where does ${date} "variable" comes from, how can I change date_format or
is it possible to write some function to reformat date?
SS
--
Carl Swan
InDepth Engineering
Geertjan Wielenga
2008-07-30 15:51:29 UTC
Permalink
Post by Carl Swan
I had the same problem until I realized that the ${date} variable was
of type String not type Date. You have to cast it to a Date type then
do the format. I needed just the year so mine looked like this.
${date?date?string("yyyy")}
That's a great tip for the User FAQ. If you don't add it, I will!

Gj
Post by Carl Swan
Hope that helps.
Carl
Hi,
I'm trying to change format of date/time in Java Class template...
from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"
/*
* ${name}.java
*
* Created on ${date}, ${time}
*/
...
"Jul 30, 2008, 3:27:05 PM"
"July 30, 2008, 3:27 PM"
I see that "Java Class template" is using FreeMarker and "JFrame
template " not...
I looked in the manual
http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html
but I don't understand how this can be used inside Java Template...
Where does ${date} "variable" comes from, how can I change
date_format or
is it possible to write some function to reformat date?
SS
--
Carl Swan
InDepth Engineering
Carl Swan
2008-07-30 16:08:37 UTC
Permalink
go ahead, I'm kind of busy

On Wed, Jul 30, 2008 at 11:51 AM, Geertjan Wielenga <
Post by Geertjan Wielenga
Post by Carl Swan
I had the same problem until I realized that the ${date} variable was of
type String not type Date. You have to cast it to a Date type then do the
format. I needed just the year so mine looked like this.
${date?date?string("yyyy")}
That's a great tip for the User FAQ. If you don't add it, I will!
Gj
Post by Carl Swan
Hope that helps.
Carl
Hi,
I'm trying to change format of date/time in Java Class template...
from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"
/*
* ${name}.java
*
* Created on ${date}, ${time}
*/
...
"Jul 30, 2008, 3:27:05 PM"
"July 30, 2008, 3:27 PM"
I see that "Java Class template" is using FreeMarker and "JFrame
template " not...
I looked in the manual
http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html
but I don't understand how this can be used inside Java Template...
Where does ${date} "variable" comes from, how can I change
date_format or
is it possible to write some function to reformat date?
SS
--
Carl Swan
InDepth Engineering
--
Carl Swan
InDepth Engineering
Geertjan Wielenga
2008-07-30 16:25:49 UTC
Permalink
Post by Carl Swan
go ahead, I'm kind of busy
Done: http://wiki.netbeans.org/FaqTemplateVariables

I tried your tip as well and it works.

Gj
Post by Carl Swan
On Wed, Jul 30, 2008 at 11:51 AM, Geertjan Wielenga
I had the same problem until I realized that the ${date}
variable was of type String not type Date. You have to cast it
to a Date type then do the format. I needed just the year so
mine looked like this.
${date?date?string("yyyy")}
That's a great tip for the User FAQ. If you don't add it, I will!
Gj
Hope that helps.
Carl
On Wed, Jul 30, 2008 at 11:17 AM, Sal Stone
Hi,
I'm trying to change format of date/time in Java Class template...
from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"
/*
* ${name}.java
*
* Created on ${date}, ${time}
*/
...
"Jul 30, 2008, 3:27:05 PM"
"July 30, 2008, 3:27 PM"
I see that "Java Class template" is using FreeMarker and "JFrame
template " not...
I looked in the manual
http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html
but I don't understand how this can be used inside Java Template...
Where does ${date} "variable" comes from, how can I change
date_format or
is it possible to write some function to reformat date?
SS
--
Carl Swan
InDepth Engineering
--
Carl Swan
InDepth Engineering
Carl Swan
2008-07-30 16:24:09 UTC
Permalink
Glad I could help.

Carl

On Wed, Jul 30, 2008 at 12:25 PM, Geertjan Wielenga <
Post by Geertjan Wielenga
Post by Carl Swan
go ahead, I'm kind of busy
Done: http://wiki.netbeans.org/FaqTemplateVariables
I tried your tip as well and it works.
Gj
Post by Carl Swan
On Wed, Jul 30, 2008 at 11:51 AM, Geertjan Wielenga <
I had the same problem until I realized that the ${date}
variable was of type String not type Date. You have to cast it
to a Date type then do the format. I needed just the year so
mine looked like this.
${date?date?string("yyyy")}
That's a great tip for the User FAQ. If you don't add it, I will!
Gj
Hope that helps.
Carl
On Wed, Jul 30, 2008 at 11:17 AM, Sal Stone
Hi,
I'm trying to change format of date/time in Java Class template...
from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"
/*
* ${name}.java
*
* Created on ${date}, ${time}
*/
...
"Jul 30, 2008, 3:27:05 PM"
"July 30, 2008, 3:27 PM"
I see that "Java Class template" is using FreeMarker and "JFrame
template " not...
I looked in the manual
http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html
but I don't understand how this can be used inside Java Template...
Where does ${date} "variable" comes from, how can I change
date_format or
is it possible to write some function to reformat date?
SS
-- Carl Swan
InDepth Engineering
--
Carl Swan
InDepth Engineering
--
Carl Swan
InDepth Engineering
Sal Stone
2008-07-31 07:42:46 UTC
Permalink
Thanks! You helped a lot!

The same is true for ${time}...

SS
Post by Carl Swan
I had the same problem until I realized that the ${date} variable was of
type String not type Date. You have to cast it to a Date type then do the
format. I needed just the year so mine looked like this.
${date?date?string("yyyy")}
Hope that helps.
Carl
Post by Sal Stone
Hi,
I'm trying to change format of date/time in Java Class template...
from this: "Jul 30, 2008, 3:27:05 PM"
to this: "July 30, 2008, 3:27 PM"
/*
* ${name}.java
*
* Created on ${date}, ${time}
*/
...
"Jul 30, 2008, 3:27:05 PM"
"July 30, 2008, 3:27 PM"
I see that "Java Class template" is using FreeMarker and "JFrame template
" not...
I looked in the manual
http://wiki.netbeans.org/FaqFreeMarker
http://freemarker.org/docs/ref_builtins_date.html
http://freemarker.org/docs/ref_directive_setting.html
but I don't understand how this can be used inside Java Template...
Where does ${date} "variable" comes from, how can I change date_format or
is it possible to write some function to reformat date?
SS
--
Carl Swan
InDepth Engineering
Loading...