Grails date type - date

In my view I have something like this:
Date: ${it.date}
which has the following output:
Date: 2011-05-24 00:00:00.0.
How can I change the Date formation so that the last part(00:00:00.0) does not appear?

Yes, you can format a date with the related tag, which is , like this:
<g:formatDate format="yyyy-MM-dd" date="${it.date}"/>
Here more info: http://www.grails.org/GSP+Tag+-+formatDate
Hope this helps. :)

If you're doing a lot of date manipulations, I'd highly suggest getting the JodaTime plugin http://www.grails.org/plugin/joda-time. It has its own tag library, and formatting the DateTime can be simply done using the toString() method.
DateTime dt = new DateTime()
println (dt.toString("YYYY-MM-dd"))
In your case you could do the following (if using JodaTime):
Date: ${it.toString("yyyy-MM-dd")}

Related

Format date and add month to it

I'm currently working with embarcadero c++, this is the first time I'm working with it so it's completely new to me.
What I'm trying to achieve is to get the current date, make sure the date has the "dd/MM/yyyy" format. When I'm sure this is the case I want to add a month to the current date.
So let's say the current date is 08/18/2016 this has to be changed to 18/08/2016 and then the end result should be 18/09/2016.
I've found that there is a method for this in embarcardero however I'm not sure how to use this.
currently I've only been able to get the current date like this.
TDateTime currentDate = Date();
I hope someone will be able to help me out here.
I figured it out.
After I've searched some more I found the way to use the IncMonth method on this page.
The example given my problem is as follows:
void __fastcall TForm1::edtMonthsExit(TObject *Sender)
{
TDateTime StartDate = edtStartDate->Text;
int Months = edtMonths->Text.ToInt();
TDateTime NextPeriod = IncMonth(StartDate, Months);
edtNextPeriod->Text = NextPeriod;
}
After looking at I changed my code accordingly to this
TDateTime CurrentDate = Date();
TDateTime EndDate = IncMonth(CurrentDate, 1);
A date object doesn't have a format like "dd/MM/yyyy". A date object is internally simply represented as a number (or possibly some other form of representation that really isn't your problem or responsibility).
So you don't have to check if it's in this format because no date objects will ever be in this format, they simply don't have a format.
You will have to do additions/subtractions on the Date object that the language or library gives you, THEN (optionally) you can format it to a human-readable string so it looks like 18/08/2016 or 18th of August 2016 or whatever other readable format that you choose.
It might be that the TRANSFER of a date between 2 systems is in a similar format, but then formatting the date like that is entirely up to you.
As for how to do that, the link you posted seems like a possible way (or alternatively http://docwiki.embarcadero.com/Libraries/Berlin/en/System.SysUtils.IncMonth), I'm afraid I can't give you an example as I'm not familiar with the tool/language involved, I'm just speaking generically about Date manipulations and they should ALWAYS be on the raw object.

Date format in Talend "2006-05-27 17:00:00.000"

I am facing an issue with Talend dates. I have tried several solutions but still an "unparseable date" error persists.
My date format is of the form : "2006-05-27 17:00:00.000"
Can you help me ?
you can use below talendDate function to parse your string into date..
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss.sss","2006-05-27 17:00:00.000")
this would take input as string and return you date.
If you don't handle the conversion yourself in a tMap but just want to use a schema, then: In your mapping configuration in the date field, you can add the following string:
yyyy-MM-dd HH:mm:ss.SSS
to set the correct format mapping for the date string. Otherwise the answer of garpitmzn is the way to go.
you should use this function in talend to fetch date:
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss.SSS","2016-01-12 12:45:00.000")

Mongodb iso datetime

I need to recover date from mongodb iso date formate by angular js. How can I recover this? please help me.
Mongodb iso date: 2013-12-28T08:30:17.795Z
My convert type: 28-12-2013 8:30:17
Maybe something like:
var date = new Date("2013-12-28T08:30:17.795Z");
$scope.displayDate = date.toLocaleString();
I really recommend http://momentjs.com/. they have a good format function.
Ex.
moment('2013-12-28T08:30:17.795Z').format('DD-MM-YYYY HH:mm:ss');
Will give the answer
28-12-2013 08:30:17
Its very easy to get the time as per mongo,
get the value in your controller from the mongoDB.
Use that value to store in the variable.
Convert it to the ISO format easily using .toISOString() method and its done.
Here is sample..
getdate.controller(..){
$scope.fromdate=date.toISOString();
console.log($scope.fromdate);
}
Now you can get in the MongoDB format..

Why does ExtJS subtract a day when formatting a date?

Using ExtJS 4.0.2, I can type the following into the console:
Ext.util.Format.date('2012-01-13', "m-d-Y");
I get 01-12-2012
Why?
I can correct it with:
Ext.util.Format.date('2012-01-13 00:00:00', "m-d-Y");
Ext.util.Format.date in Ext 4.0.2 uses a Date object or a String (your case). This string is parsed using the native Date.parse() using the UTC time zone.
Try to explicitly parse it using Ext.Date.parse:
var dt = Ext.Date.parse("2012-01-13", "Y-m-d");
Ext.util.Format.date(dt, "m-d-Y");
This problem exists in Ext3, but the solution is slightly different:
var dt = '2012-01-31'; //date string
dt = Date.parseDate(dt, "Y-m-d");
Ext.util.Format.date(dt, 'm/d/Y'); //returns 01/31/2012
If you're unable to use Gregor's answer (e.g. filling a grid), note that changing the input to a non ISO 8601 date format will avoid the UTC parsing as well. For example
Ext.util.Format.date('01/13/2012', "Y-m-d");
will give 2012-01-13

Getting a GWT timestamp in UTC format

I am trying to get the current timestamp and convert it into a UTC date for an XML file.
I am using this
import java.util.Date;
import java.util.TimeZone;
import com.google.gwt.i18n.client.DateTimeFormat;
DateTimeFormat.format( new Date(), TimeZone.getTimeZone("UTC"));
but am getting the following error
The method format(Date, TimeZone) in
the type DateTimeFormat is not
applicable for the arguments (Date,
TimeZone)
I need the output as "yyyy-mm-ddThh:mm:ssZ"
Use com.google.gwt.i18n.client.TimeZone.createTimeZone(0) to create a UTC TimeZone object, and then use that in DateTimeFormat.format(Date, TimeZone).
You can use apostrophe to indicate literals in a DateTimeFormat pattern.
eg. "HH'o''clock'"
So, the formatter you need would look something like this:
DateTimeFormat formatter = DateTimeFormat.getFormat("yyyy-mm-dd'T'HH:mm:ssZ");
I tried it out. It gave me an output in format 2010-16-29T08:16:23+0530
Is this what you are looking for?
You should provide a com.google.gwt.i18n.client.TimeZone instead of java.util.TimeZone