velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: I need help with date format
Date Tue, 13 Nov 2007 17:03:42 GMT
On Nov 13, 2007 6:57 AM, JoseBovet <jose.bovet@gmail.com> wrote:
>
> thanks guy's
> I have tried to follow your's steps steps but nothing, I'm trying with the
> following:
>
> Class FichaSDDCTRL, I am using SpringFramework
>
> public class FichaSddCtrl implements Controller {
>
>         private SddService sdd_service;
>
>         public void setSdd_service(SddService sdd_service) {
>                 this.sdd_service = sdd_service;
>         }
>
>
> /***************************************************************************
>          * Método para evaluar id del sdd
>          *
>          * @param Numero
>          *            a evaluar
>          * @return Boolean
>          */
>         public static Boolean isNumeric(String aEvaluar) {
>
>                 try {
>                         Integer.parseInt(aEvaluar);
>                         return true;
>                 } catch (NumberFormatException nfe) {
>                         return false;
>                 }
>
>         }
>
>         /** Logger for this class and subclasses */
>         protected final Log logger = LogFactory.getLog(getClass());
>
>         public ModelAndView handleRequest(HttpServletRequest arg0,
>                         HttpServletResponse arg1) throws Exception {
>
>                 Map model = new HashMap();
>                 // TODO Auto-generated method stub
>
>                 Integer id_sdd;
>                 Boolean esNumero;
>                 SdddetExample criterio = new SdddetExample();
>                 List<Sdddet> detalleList = new ArrayList<Sdddet>();
>                 Sddenc encabezado = new Sddenc();
>
>                 // llamo método isNumeric y le paso el id
>                 esNumero = isNumeric(arg0.getParameter("id"));
>
>                 // valido que no venga vacio y que el retorno del método isNumeric sea
>                 // true
>                 if (arg0.getParameter("id") != "" && esNumero == true) {
>
>                         id_sdd = Integer.parseInt(arg0.getParameter("id"));
>
>                         encabezado = sdd_service.selectEncabezadoSddEncByIdSdd(id_sdd);
>                         detalleList = sdd_service.selectDetalleSddByIdSdd(id_sdd);
>
>
>                          DateTool datetool = new DateTool();
>
>
>                         model.put("date", datetool);
>                         model.put("encabezado", encabezado);
>                         model.put("detalleList", detalleList);
>                 }
>
>
>
>
>                 return new ModelAndView("ficha_sdd", model);
>         }
>
> }
>
> In velocity ficha.vm:
>
> #set($fechaVenta =$!encabezado.getFectra()))
> $!date.format('yyyy-MM-dd',$fechaVenta)
>
>
> in the vm page the value of fechaVenta is 1970-01-01
> but the value of $!encabezado.getFectra() is 20071112
>
> I need help??? :(

try this:

$date.format('yyyy-MM-dd', $date.toDate('yyyyMMdd', "$encabezado.fectra"))

the trick is that your 20071112 integer is not an automatically
recognized date format, so you need to turn it into a string and tell
DateTool.toDate() what format it is in.  then you can pass the
resulting Date object into the format() method and have DateTool
reformat it into the form you want.

but honestly, you will get better performance on this routine if you
write your own MyDateTool class (which could extend DateTool if you
wanted) with a function that does all of this automatically.  this
would simplify your template into:

$date.reformat($encabezado.fectra)

>
>
>
>
>
>
>
> Nathan Bubna wrote:
> >
> > you can write a little helper tool to do it:
> >
> > public MyDateTool {
> >   public Date format(int oracleDate) {
> >      //TODO: the actual conversion here
> >   }
> > }
> >
> > or use this one:
> > http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html
> >
> > On 11/7/07, JoseBovet <jose.bovet@gmail.com> wrote:
> >>
> >> hi guy's
> >>
> >>
> >> I have a  problem with a date format,
> >> I need format a Integer to Date  or Integer to String
> >> a example:
> >>
> >> int number1 20070101 to date format (01-01-2007)
> >> or
> >>
> >> int number1 20070101 to String format (01-01-2007)
> >>
> >> number1 is get for  method in a DB oracle!!!
> >>
> >>
> >> greetings°
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13636581
> >> Sent from the Velocity - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >> For additional commands, e-mail: user-help@velocity.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/I-need-help-with-date-format-tf4767519.html#a13727488
>
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message