Issue saving a string as ISO date format

I'm trying to save a date to MongoDB from FullCalendar in my Grails application.

I'm trying to parse the string 2015-12-27T00:00:00.000Z into the below format:

def startDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.start)
def endDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.end)

But, weirdly when I print the formatted date, I get Sun Dec 28 05:30:00 IST 2014. I don't know what or how that particular date is picked.

Answers


You should use lowercase y for year. Uppercase Y is for "Week year".

new Date().parse("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "2015-12-27T00:00:00.000Z")
===> Sat Dec 26 19:00:00 EST 2015

import java.text.SimpleDateFormat;
println new SimpleDateFormat("yyyy-MM-dd HH:mm:ssX").parse("2018-07-30 09:57:15 +0800")

Need Your Help

Can I send variables to the same JavaScript from two pages?

javascript php html forms variables

I have 2 pages where the user gives data that needs to be stored (the 1st is a string from the first page and the rest comes from a form from the second page). This webpage is not on a server, its ...

How to gen map<string, int>matrix from dat file

c++ file

I have a .dat file and want to get a map from it