NetBeans Code Templates ${date}?
Asked Answered
A

7

11

I have this code template in Eclipse

@since ${date}

when entered i get something like this :

@since 4.8.2009

But when i add the same template (@since ${date}) to NetBeans it outputs

@since date

Can someone help ?

No answer yet ? Is this not possible in Netbeans ???

Axel answered 4/8, 2009 at 11:39 Comment(0)
S
12

Something like the following example should doing the job :

${date?date?string("yyyy")}.${date?date?string("MM")}.${date?date?string("dd")}
  • yyyy => year on 4 elements (ex: 2012)
  • MM => Month on 2 elements (ex: march -> 03)
  • dd => Day of the month on 2 elements (ex: 23)
  • . => separator you want to separate each fields (ex: - or / or . or smth else) You should have to check about available format somewhere in the netbeans help (sorry I don't find out informations about this for now). I see that's a very old post, but if it may usefull for someone ... regards. ollie314
Startling answered 14/3, 2012 at 9:13 Comment(3)
Thanks for the input i now use Eclipse but its always good to have ones question answerd.Axel
This can be further simplified to just ${date?date?string("yyyy.MM.dd")}Albaalbacete
Working with netbeans 8.2, and also simplified version on comment by fyryeDamson
A
5

Not wanting to raise the dead with this post, but I thought it worth mentioning so I signed up to SO specifically to clarify, since Ollie314 saved me a lot of time.

The format ollie314 used is correct (for version 7.1+ at least) BUT just to be clear, if it's not displaying correctly it may be due to your system locale settings, if outside of USA. Be sure to include <#setting locale="en_AU"> (replace en_AU with your locale id) in the template you are editing, prior to the date?date?string cast declaration, or it will not work. If you place it in the user settings it won't cast the date string in the template and you will generate errors in your template output.

The documentation from Netbeans isn't particularly clear on that. Still, best IDE ever :)

Arcuate answered 29/9, 2012 at 8:30 Comment(0)
S
2

Inserting ${date?date?string("yyyy")} within your template will do the trick (if you want year only)

Sorayasorb answered 9/7, 2010 at 10:36 Comment(0)
T
1

Note: With NetBeans 6.5/6.7, if you do not find that template, you could create it.

See this tutorial.

Termagant answered 4/8, 2009 at 11:58 Comment(1)
Thanks for the answer. i know i can create my own templates, but the problem is with the missing ${date} variable or something equal. ${date} only returns "date"Axel
L
1

I'm pretty sure this is not possible in Netbeans, or at least not worth the amount of trouble. It's possible that you could author your own Netbeans module, add a code template to the module (in which you might be able to put the ${date} as an extra variable, I'm not sure), and then add the module to Netbeans. But you could also just type the date in, which, unless you type it several thousand times per day, would probably take less time.

Lenin answered 6/8, 2009 at 20:31 Comment(1)
Thanks David for the answer. I guess that you are right. The only solution that i have found is to simply change the code template every day to get the right date.Axel
U
0

Your snippet looks like freemarker code. This is used in Netbeans for file templates (Tools -> Templates). If you put ${date} in a file template it will get transformed when the file is created to the current date. If you're trying to use it as a code template I don't know how that works.

Urolith answered 6/8, 2009 at 20:46 Comment(1)
I have noticed this and that´s why i thought that i could find something similar to ${date} for the code templates. Thanks JRL by the way for your findings.Axel
S
0

Even simpler, use ${date?date?string.yyyy}

Spartacus answered 25/5, 2021 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.