- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, can anyone confirm this Happy-New-Year-feature (found on a german windows Server 2k12R2, with vCenter Orchestrator 5.5.3):
- Create a new Workflow
- Add one scriptable Task
Use the following content for the scriptable Task:
var myTimestamp = System.getCurrentTime();
var myDate = new Date();
myDate.setTime(myTimestamp);
System.log("getYear from DateObject: "+(myDate.getYear()+1900));
System.log(System.formatDate(myDate, "YYYY-MM-dd HH:mm:ss"));
Run the workflow.
I would exspect in the log lines:
2016
2016-01-02 13:00:00
But I get:
2016
2015-01-02 13:00:00
The clock on the server is correct.
A SR is already open but I'm interested if its only on "my" server or on other servers, too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
This is not a bug but kind of expected behavior.
Your date pattern uses uppercase 'Y' for year. According to spec http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 'Y' is not 'year' but 'week year'. To get the 'year', you need to use lowercase 'y'. Check the following page for what is the difference between year and week year
http://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#week_year
To fix your code, just replace YYYY with yyyy. The pattern should become "yyyy-MM-dd HH:mm:ss"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the solution.
I never heard of "week of year" before ...