2

I have a very specific C++ project, and I use a NetBeans.

Reason for it is because we need to have a specific timestamps, and I found NetBeans templates a great tool for inserting an automatic header with all the relevant stuff.

I manage set everything up nicely, but I can't figure out how to set up the time format in the header template.

Currently it shows this:

Created on April 6, 2017, 2:18 PM

But since I work in Central Europe, I need a 24h hour format so I could have something like

Created on 06.04.2017. at 14:18

I found on how to change a date format here, but it doesn't work for times for some reason.

I even tried with using FreeMaker's template language reference, so I created a variable time that looks like this:

<#assign dateTime = .now>
<#assign time = dateTime?time>

${time?iso("Europe/Zagreb")}

But it still didn't change anything.

Now my template looks like this:

// -*- C++ -*-
<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">

<#assign aDateTime = .now>
<#assign time = aDateTime?time>

<#include "${project.licensePath}">

/* 
 * File:   ${NAME}.${EXTENSION}
 * Author: ${user}
 *
 * Created on ${DATE} at ${time?iso("Europe/Zagreb")}
 */

#ifndef ${GUARD_NAME}
#define ${GUARD_NAME}



#endif  /* ${GUARD_NAME} */

Is this possible to be changed at all, and how?

Any help is appreciated.

mutantkeyboard
  • 1,614
  • 1
  • 16
  • 44
  • 1
    Are you sure you are editing the right template? Using exactly the template you posted I get the following: `Created on April 6, 2017 at 16:14:23+02:00`. Which shows 24 hour time. – acm Apr 06 '17 at 14:22
  • @acm You're correct. I edited a wrong file. It was obviously a long day at work :) – mutantkeyboard Apr 06 '17 at 14:44
  • I'm struggling with this too. I find it sad and frustrating that even in 2017, we're still struggling with basic localization. Netbeans should at a minimum draw on the user's desired localization format rather than overriding user choice with a format specific to one country (or, to be blunt, Netbeans should refrain from being an arrogant actor). If that's too difficult, then use ISO8601 format, which is standard in the US and most other countries. – EBlake Jun 06 '17 at 23:00

1 Answers1

2

In your question you link a resource (THANKS for that!!!) suggesting the following for dates:

${date?date?string("dd.MM.yyyy")}

I tried the same for time and it works well:

${time?time?string("HH.mm.ss")}

BTW I also tried producing some errors and got some nice error messages stating what NB expects and what it gets pretty clearly:

${date?time?string("hh.mm.ss")}
${time?date?string("hh.mm.ss")}
${time?datetime?string("hh.mm.ss")}
${date?datetime?string("hh.mm.ss")}

produced:

  • Error: on line 20, column 6 in Templates/Classes/Class.java The string doesn't match the expected date/time format. The string to parse was: "11-Jan-2018". The expected format was: "HH:mm:ss".
  • Error: on line 21, column 6 in Templates/Classes/Class.java The string doesn't match the expected date/time format. The string to parse was: "13:40:27". The expected format was: "dd-MMM-yyyy".
  • Error: on line 22, column 6 in Templates/Classes/Class.java The string doesn't match the expected date/time format. The string to parse was: "13:40:27". The expected format was: "dd-MMM-yyyy HH:mm:ss".
  • Error: on line 23, column 6 in Templates/Classes/Class.java The string doesn't match the expected date/time format. The string to parse was: "11-Jan-2018". The expected format was: "dd-MMM-yyyy HH:mm:ss".
tomorrow
  • 1,260
  • 1
  • 14
  • 26