cancel
Showing results for 
Search instead for 
Did you mean: 

change date format

Former Member
0 Kudos

Hi everybody,

i am giving date in front end view filed .

but this date is not matchable in java date .

how convert the webdynpro date to as java acceptable date format.

i am getting error while mapping the date attribute from backend to creation of layout in view.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Eswar,

if u connecting wid ur database then it might b compatible wid java.sql.Date n u might b using java.util.Date class..

thre r 2 ways for defining date either java.util or java.sql

it depends whcih is compatible wid ur backend..

if u wnna use java.sql u will hav to type cast ur date at some places so that it can b converted into java.sql from java.util..generally we use java.util

u can apply date formatter to for making input in proper date format..

import java.sql.Date;

public static final java.text.SimpleDateFormat FORMATTER =
		new java.text.SimpleDateFormat("dd.MM.yyyy");


private Date getDate(java.lang.String dateString) throws Exception {

		try {

			return (Date) FORMATTER.parse(dateString);

		} catch (java.text.ParseException pe) {

			pe.printStackTrace();

			throw new Exception("The date has to be in format dd.MM.yyyy, for example 21.04.2004");

		}

hope it hlps..

Regards,

Khushboo

Answers (5)

Answers (5)

Former Member
0 Kudos

i want to convert the date

timestamp type to date ,

and date to time stamp.

tell me if it possible

Former Member
0 Kudos

Hi,

Following is the way to get TimeStamp from a date

Ex:


// f.i. your date has a value on now
Date yourDate = (Date) Calendar.getInstance().getTime();
// conversion
Timestamp convertedDate = new java.sql.Timestamp(yourDate.getTime());

TimeStamp to Date
Date dt = new Date(convertedDate.getTime());

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

You could create a simple type of date datatype and set the format to the one required. Set your context attribute's type property to this simple type.

Regards,

Murtuza Kharodawala

Former Member
0 Kudos

Hi Murtuza Kharodawala,

how to create simple type as u told , could explain briefly,

what is advantage instead of selecting the type date .to go simpletype.

and how it convert to java util date format.

Former Member
0 Kudos

Hi,

Goto your local Dictionary>Simple Type> Right Click Create New Simple Type

Specify the name and the package and set the type as date.

Open the representation tab wherein you could specify the format of the date eg. dd/MM/yyyy.

If you have a static date format for all the applications then you could just create a simple type and set the context of simpletype. If you select the type date then you don't have the flexibility to sepcify its format which you have when you go for simpletype.

Hope this helps you.

Regards,

Murtuza

Former Member
0 Kudos

Eswar,

What data type you have selected for the date context attribute, if you choose date as type of that context attribute, you don't have to worry about the date format, system will handle it for your self. And also it will provide you date selection option.

Regards,

Jawed Ali

P.S.

Incase if you want to change date format then you have to change the locale of the registered used on EP.

former_member197348
Active Contributor
0 Kudos

Hi Eswar,

from backend you get java.sql.Date. So better to create same type of date attribute in Web dynpro application .

Date currDate = new Date(System.currentTimeMillis());

and in imports

import java.sql.Date;

Regards,

Siva

Former Member
0 Kudos

Hi,

use this to pass the date to backend,

new Date(Calendar.getInstance().getTimeInMillis())

example to pass current date to attribute 'a' of date type..

a.setDate(new Date(Calendar.getInstance().getTimeInMillis()));

thanks,

ramesh.