String to date conversion problem
Hai braniees,
i am new to java.I have a problem in converting string to date.my code is this
dob="2/05/2005";
SimpleDateFormat sf=new SimpleDateFormat("dd/MM/yyyy");
Date dt=sf.parse(dob);
i this i am getting the error in the last line.the error is
" Unhandled exception type ParseException"
I am not able to getrid of this.
Thanks
anieshuk
I would advise against doing what ranjithcp suggested unless you are such a perfect programmer that you'll never get invalid data into your methods. Also what ranjithcp has failed to mention is that you'll have to put the throws instruction all over your code right up to your main method otherwise your just moving your error message up through your program.
You should always try and handle checked exceptions not throw them.
Similar Messages
-
i have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion.
i wrote the method but it not workig
My method is
-(NSDate *)dateformstr:(NSString *)str
NSString *date = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSDateFormatter *dateFormate = [[NSDateFormatter alloc] init];
[dateFormate setDateFormat:@"yyyy-MM-dd'T'HH:mm:sssZZZZ"]
// NSDate *formatterDate = [dateFormate dateFromString:str];
return formatterDate;
but i did not the value and if i try othere formate i is working but my requiremet format is 2012-04-30T23:48:55.727-07:00.
can any help it out in this senario.Sorry Butterbean, but I'm interested in the answer to your question myself.
I've spent a few hours transfering my library from one computer to another and then find out that my ratings didn't transfer. Like you, I've spent many hours rating my 2000+ songs. I'm sure you have more, nevertheless, I want to find out how to get those ratings. They still show in my iTunes on my laptop but, when I go to the iTunes folder and display the details of at song, no rating is there. If you find out how to get them to display there in the iTunes folder, it seems that would be the key.
Hope you get your answer soon. -
R/3 Date Conversion problem
How to convert the R/3 Date to Array.
If you are receiving a date field from R/3, please use <b>SimpleDateFormat</b>(class) to re-arrange your date in any fashion. Along with the method <b>format</b> you can just have your date in any format :
DD-MM-YYYY
MM-DD-YY
DD-MMMMM-YYYY (Month will be spelled out as text)
All you need to do is :
SimpleDateFormat sf = new SimpleDateFormat("DD/MM/YYYY");
sf.format(myDateField);
Since R/3 date conversion is usually for this reason, I mentioned the above class.
Regards,
Subramanian V. -
Char to Date conversion problem - again!
Hi,
in order to make date selection 'more attractive' for end users I have been tasked with presenting a text field with 'January 2010', 'February 2010' etc to the end users for their prompts.
So far so easy...
However, I then need to use the values to derive either dates, or years, or date numbers.
This all works fine during development when I am testing using a default parameter thus; -
'@{MYMONTHYEAR}{September 2010}' - which is fed into various very complex functions.
BUT - when I try to use the report in conjunction with the parameter I get; -
'The evaluation of the index 6 expression on row count -1 failed. [nQSError: 46046] Datetime value 2010/09/01 does not match the specifiied format'
However, cast('2010/09/01' as date) works fine... and convoluted as the logic of my functions is, the fundamental char to date conversion is exactly in this format.
Anyone shed any light on this, give me a guaranteed way to handle char to date conversion?
thanks,
Robert.Hi,
I tried your workaround case when 1=2... but I still get the same error....
Not when I have the format from my default value, but when I get the value from a dashboard prompt in a page.
The full error is; -
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 46046] Datetime value 2012/09/01 does not match the specified format. (HY000)
SQL Issued: SELECT s_0, s_1, s_2, s_3, s_4, s_5, s_6, s_7, s_8, s_9, s_10, s_11, s_12, s_13, s_14, s_15, s_16, s_17, s_18, s_19, s_20, s_21, s_22, s_23, s_24, s_25, s_26, s_27, s_28, s_29, s_30, s_31, s_32, s_33, s_34, s_35, s_36, s_37, s_38, s_39, s_40, s_41, s_42, s_43, s_44, s_45, s_46, s_47, s_48, s_49, s_50, s_51, s_52, s_53, s_54, s_55, s_56, s_57 FROM ( SELECT 0 s_0, "Vivaldi Detail"."Product Global Hierarchy"."Tobacco Category Groups" s_1, "Vivaldi Detail"."Product Global Hierarchy"."Tobacco Category" s_2, "Vivaldi Detail"."Product Global Hierarchy"."Total Tobacco Products" s_3, FILTER("Vivaldi Detail"."Fact Sales Detail"."SOM %" USING ("Vivaldi Detail"."Time"."Year" =cast((cast(right('September 2012',4) as integer)-1) as char(4)))) s_4, FILTER("Vivaldi Detail"."Fact Sales Detail"."SOM %" USING ("Vivaldi Detail"."Time"."Year" =cast((cast(right('September 2012',4) as integer)-2) as char(4)))) s_5, FILTER("Vivaldi Detail"."Fact Sales Detail"."SOM %" USING ("Vivaldi Detail"."Time"."Year" =cast((cast(right('September 2012',4) as integer)-3) as char(4)))) s_6, FILTER(FILTER("Vivaldi Detail"."Fact Sales Detail"."SOM %" USING ("Vivaldi Detail"."Time"."Year" =cast((cast(right('September 2012',4) as integer)-1) as char))) USING "Vivaldi Detail"."Time"."Month Number" <=month(CASE WHEN 1=2 THEN CURRENT_DATE ELSE cast(right('September 2012',4)||'/'||CASE left('September 2012',LOCATE(' ','September 2012')-1) WHEN 'January' THEN '01/01' WHEN 'February' then '02/01' when 'March' then '03/01' when 'April' then '04/01' when 'May' then '05/01' when 'June' then '06/01' when 'July' then '07/01' when 'August' then '08/01' when 'September' then '09/01' when 'October' then '10/01' when 'November' then '11/01' ELSE '12/01' END as date)END)) s_7, FILTER(FILTER("Vivaldi Detail"."Fact Sales Detail"."SOM %" USING ("Vivaldi Detail"."Time"."Year" =right('September 2012',4))) USING "Vivaldi Detail"."Time"."Month Number" <=month(CASE WHEN 1=2 THEN CURRENT_DATE ELSE cast(right('September 2012',4)||'/'||CASE left('September 2012',LOCATE(' ','September 2012')-1) WHEN 'January' THEN '01/01' WHEN 'February' then '02/01' when A brief sample of a typical formula which causes this is; -
FILTER(FILTER(FILTER("Fact Sales Detail"."SOM %" USING ("Time"."Year" = right('@{MYEAR}{September 2010}',4))) USING ("Time"."Month Number" = 2)) USING "Time"."Month Number" <= month(CASE WHEN 1=2 THEN CURRENT_DATE ELSE cast(right('@{MYEAR}{September 2010}',4)||'/'||CASE left('@{MYEAR}{September 2010}', LOCATE(' ','@{MYEAR}{September 2010}') -1) WHEN 'January' THEN '01/01' WHEN 'February' then '02/01' when 'March' then '03/01' when 'April' then '04/01' when 'May' then '05/01' when 'June' then '06/01' when 'July' then '07/01' when 'August' then '08/01' when 'September' then '09/01' when 'October' then '10/01' when 'November' then '11/01' ELSE '12/01' END as date) END ))The September 2010 default being EXACTLY what is selected from the dashboard prompt when testing. It does not error, but returns no data in isolation, but when when from the prompt it errors...
And the date format, if fed into a cast ('2012/09/01' as date) does not error.
Anyone help - this is really driving me mad, syntax is good - it should work!!!
thanks,
Robert. -
Date conversion problem.
I use 2 adaptive RFC function with a r3 backend system:
1- Search
2- Update
The first works fine, I show the data, one of the fields is a date (with r3 Date format) binded and in the web dynpro is showed in inputfield, with a little calendar icon on the right.
I have problem with the second one. Cause I use the same inputfield for both RFC. I bind in design time with the Search RFC and for the update I pass the changed values to the 2nd RFC trought coding.
What I want is just to save in a Variable, the value of the binded UI element, with the string type I have no problem, but when I wanna save my date field in a String It say that the conversion cannot be done.
<u>EXAMPLE:</u>
String value1 = wdContext.currentTable_CelElement().getNumcel();
I wanna accomplish that example but With Date format. So the question would be How can I save in a Variable a Date format field of R3.
<b>"?" </b>value2 = wdContext.currentTable_CelElement().getFecha();
ThxHi!
I think that this problem occurs because of different Date formats in your Web Dynpro Application: The R/3-Date format is mapped to java.sql.Date, and for your variable you probably use java.util.Date.
If so, try to use the sql.Date for your variable, too, or make a conversion like this:
java.util.Date myDate = new java.util.Date(wdContext.currentTable_CelElement().getFecha().getTime());
Regards,
Thomas -
Hi,
I need to convert a string to a Date format.
Input string can be in 2 formats: "mm-dd-yy" and "yyyy-mm-dd".
Thanks....java.util.Date date = new java.util.Date();
sd = new java.text.SimpleDateFormat("yyyy-MM-dd");
System.out.println(sd.format(date));
sd = new java.text.SimpleDateFormat("MM-dd-yy");
System.out.println(sd.format(date)); -
MS SQL Server 2005 Data Conversion Problem
Hello all,
I'm using the Microsoft JDBC Driver with SQL Server 2005 and getting an exception from the database server indicating that it is attempting to convert an nvarchar to an int (SQL Error 8114). This is the stack trace and code. I've exhausted all my resources... anybody have an idea?
com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to int.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getPrepExecResponse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement (Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(Unknown Source)
at com.boeing.ict.workmonitor.swing.JMainFrame$33.insertIntoDB (JMainFrame.java:986)
at com.boeing.ict.workmonitor.utils.SafeUDPWorker.respond(SafeUDPWorker.java:65)
at com.boeing.ict.workmonitor.utils.SafeNetWorker.runWork(SafeNetWorker.java:113)
at com.boeing.ict.workmonitor.utils.SafeNetWorker.access$000 (SafeNetWorker.java:21)
at com.boeing.ict.workmonitor.utils.SafeNetWorker$1.run(SafeNetWorker.java:59)
at java.lang.Thread.run(Unknown Source)
private void listenToCOTMessages() {
// the listener has not started yet.
if (cotMessageWorker == null) {
cotMessageWorker = new SafeUDPWorker() {
public void insertIntoDB(Iterator<NameValuePair> nvPairs) {
try {
int numParameters = 0;
if (isDebugMode()) {
System.err.println("Entered insertIntoDB");
while (nvPairs.hasNext()) {
NameValuePair pair = nvPairs.next();
// Aircraft callsign
if (pair.getName().equalsIgnoreCase("callsign")) {
cotStatement.setString(1, pair.getValue());
// debug code
System.err.println("{1} " + pair.getValue());
cotStatement.setString(2, pair.getValue());
// debug code
System.err.println("{2} " + pair.getValue());
numParameters++;
if (numParameters > 7)
break;
// Aircraft altitude (meters)
else if (pair.getName().equalsIgnoreCase("hae")) {
int height = Integer.parseInt(pair.getValue());
height = (int)((height * 39.37) / 12);
cotStatement.setInt(3, height);
// debug code
System.err.println("{3} " + height);
numParameters++;
if (numParameters > 7)
break;
// aircraft latitude N/S (+/-)
else if (pair.getName().equalsIgnoreCase("lat")) {
String rawLatitude = pair.getValue();
// we have a south latitude
if (rawLatitude.charAt(0) == '-') {
// we need to append an " S"
} else {
rawLatitude = rawLatitude.substring(1) + " S";
cotStatement.setString (4, rawLatitude);
System.err.println("{4} " + rawLatitude);
numParameters++;
if (numParameters > 7)
break;
// aircraft longitude E/W (+/-)
else if (pair.getName ().equalsIgnoreCase("lon")) {
String rawLongitude = pair.getValue();
// we have a west longitude
if (rawLongitude.charAt (0) == '-') {
rawLongitude = rawLongitude.substring(1) + " W";
cotStatement.setString(5, rawLongitude);
// debug code
System.err.println("{5}" + rawLongitude);
numParameters++;
if (numParameters > 7)
break;
// aircraft course
else if (pair.getName().equalsIgnoreCase("course")) {
cotStatement.setString(6, pair.getValue());
// debug code
System.err.println("{6} " + pair.getValue());
numParameters++;
if (numParameters > 7)
break;
// we have a speed number
else if (pair.getName ().equalsIgnoreCase("speed")) {
cotStatement.setInt(7, Integer.parseInt(pair.getValue()));
System.err.println("{7} " + pair.getValue ());
numParameters++;
if (numParameters > 7)
break;
else {
continue;
// execute the callable statement
cotStatement.execute();
} catch (SQLException ex) {
ex.printStackTrace();
// statusPanel.getStatusTextArea().append( ex.getMessage());
// set the debugging mode
cotMessageWorker.setDebugMode(debugMode);
// set the output area for the worker
cotMessageWorker.setMessageArea(cotTextArea);
String portField = cotPortTextField.getText();
// get the port setting from the portTextField
if (portField.length() != 0) {
try {
cotMessageWorker.setPort(Integer.parseInt(portField));
} catch (NumberFormatException nfe) {
cotPortTextField.setBackground(Color.RED);
cotMessageWorker.setStatusArea(statusPanel.getStatusTextArea());
// set the java.sql.Statement object to do the data insertion
if (cotStatement != null)
cotMessageWorker.setSqlStatement(cotStatement);
cotMessageWorker.start();
} else { // the listener has started
// there are no errors generated for making multiple resume requests
cotMessageWorker.resumeRequest();
}Ideas? Not really, there's nothing wrong-looking about your code, but maybe I could ask some dumb questions.
Has this code never worked, or does it usually work but occasionally this error occurs? Have you just switched to SQL Server 2005 from 2000 and the error started happening?
Does the table you are inserting to only have those 7 columns, or are there others that are getting default values? Does it contain auto-generated identity columns? Are you sure you're using the right table in the right database? -
Hi,
Am facing problem in flex that using web services am getting the data in xml format (below provided) am not able to provide the data from xml to datagrid. Am getting the data in datagridcolumn with the tag also. I need only data to be displayed without the child tag in the datagrid.
XML Format output as below:
<UDSObjectList>
<UDSObject>
<Handle>cr:400503</Handle>
<Attributes>
<Attribute DataType="2005">
<AttrName>ref_num</AttrName>
<AttrValue>671</AttrValue>
</Attribute>
<Attribute DataType="2005">
<AttrName>impact</AttrName>
<AttrValue>5</AttrValue>
</Attribute>
<Attribute DataType="2005">
<AttrName>priority</AttrName>
<AttrValue>1</AttrValue>
</Attribute>
</Attributes>
</UDSObject>
</UDSObjectList>
Attached the screenshot of output for your reference. The screenshot showing the datawith tag and here is other problem is for request id and impact and priority columns showing three columns data in all the columns.
Actual data is as below:
Request Id is 671
Impact is 5
Priority is 1
but the data is shown in all the columns not shown in related columns.
Thanks in advance..........Can anyone provide a solution. As this problem was facing since long time.
Thanks -
Time String to Timestamp Conversion Problem
Hi,
I attempted to convert time string to timestamp but I failed. What is the wrong with it? I need a timestamp to create waveforms.
Egemen
Solved!
Go to Solution.
Attachments:
Time String to Timestamp.png 18 KBYou are right Gogineni, when I got the error, I was using %S in the format string for Format Date/Time String function and %3u in the format string for Scan From String.
I found the solution in this thread - use %S%3u in both places.
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help. -
Phillips date conversion problems
Hi chaps,
I am trying to convert a CHAR7 field from a phillips date, into an Oracle date format. The following expression does not work:
SELECT TO_DATE('2006214', 'YYYYWWD') FROM dual
(gives error "ORA-01820: format code cannot appear in date input format")
However, if I try to convert the system date the other way to this format, it works:
SELECT TO_CHAR(sysdate, 'YYYYWWD') FROM dual
I am obviously missing something obvious!!? Does anyone have any ideas?
thanks in advance
MikeYep I had a couple of bugs, last substr should have been 7 not 6, also week 1, day 1 should be Jan 1st (I think) so I had to remove a week and a day from each.
Now I get
SQL> exec :d := '2006214'
PL/SQL procedure successfully completed.
SQL> select trunc(to_date(substr(:d,1,4),'yyyy'),'y')
2 + (to_number(substr(:d,5,2)) * 7) - 7
3 + to_number(substr(:d,7)) - 1
4 from dual;
TRUNC(TO_D
05-24-2006
SQL> exec :d := '2006011'
PL/SQL procedure successfully completed.
SQL> /
TRUNC(TO_D
01-01-2006
SQL> exec :d := '2006021'
PL/SQL procedure successfully completed.
SQL> /
TRUNC(TO_D
01-08-2006
SQL> -
Regarding conversion of String to Date
Hi
Ravi here and I am getting the following exception when i am working with String to date conversion.As i am working in LAN this code is working for all others .This problem is with my system only.This is not supporting with yyyy-MM-dd format.One more thing in my system only we installed VisualStudio.Is that a problem for this exception.I am using Myeclipse
Plzzzzzzzzzzz help me I got strucked .
Thanks in advance
Code:
public void testSaveDates() throws HibernateException, ParseException{
try{
Date date=new Date();
String str1 ="2006-05-06";
Date dateFormatter = new SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;
System.out.println(dateFormatter);
catch(Exception e){
e.printStackTrace();
Exception:
java.text.ParseException: Unparseable date: "2006-05-06"
at java.text.DateFormat.parse(DateFormat.java:335)
at chaitanya.MyTest.testSaveDates(MyTest.java:282)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)Date date=new Date();You don't need this line.
Date dateFormatter = new
er = new
SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;As already told, you don't need the single quotes. And you don't need two semi-colons - that's unnecessary.
I just wrote a sample code to test that out. Check it and see for yourself.
import java.text.SimpleDateFormat;
public class Test {
public static void main(String[] args) throws Exception {
System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse("2005-04-18"));
System.out.println(new SimpleDateFormat("'yyyy'-'MM'-'dd'").parse("2005-04-18"));
}Output:
Mon Apr 18 00:00:00 EDT 2005
Exception in thread "main" java.text.ParseException: Unparseable date: "2005-04-18"
at java.text.DateFormat.parse(DateFormat.java:335)
at Test.main(Test.java:6)I wonder why it is not feasible to write a quick sample code. -
Problem with String to Int conversion
Dear Friends,
Problem with String to Int conversion
I am having a column where most of the values are numeric. Only 4 values are non numeric.
I have replaces those non numeric values to numeric in order to maintain the data type.
CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END
This comes the result as down
Grade
_0_
_1_
_10_
_11_
_12_
_13_
_14_
_15_
_16_
_17_
_18_
_19_
_2_
_20_
_21_
_22_
_23_
_24_
_3_
_4_
_5_
_6_
_7_
_8_
_9_
Refresh
Now I want to convert this value to numeric and do some calculation
So I changed the formula as below
cast (CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as INT)
Now I get the following error
View Display Error
_ Odbc driver returned an error (SQLExecDirectW)._
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
_State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
Refresh
Could anybody help me
Regards
Mustafa
Edited by: Musnet on Jun 29, 2010 5:42 AM
Edited by: Musnet on Jun 29, 2010 6:48 AMDear Kart,
This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
I have done the code like following and it works fine
Thanks again for your support
Regards
Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int) -
Facing Problem in parsing a string to date
Hi,
I was trying to change a string into date with date format ("EEEE,MMM,d,h:mm") but I always get the year as 1970.
here is my code
String strDate="Saturday,Jan 19 7:31";
String dateFormat3="EEEE,MMM,d,h:mm";
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat3);
result1=myDateFormat.parse(strDate);
catch(ParseException pe) {
System.out.println("ERROR: could not parse date in string \"" +
}any solution for it.This is my actual code
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TestingDate {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
String dateFormat="EEEE, MMM d h:mm a";
Date test=new Date(2007,0,19, 19, 31);
System.out.println(" original date is "+test);
String stringResult=DateToString(test,dateFormat);
System.out.println("Date to string is "+stringResult);
Date dateResult=stringToDate(stringResult,dateFormat);
System.out.println(" String to date is "+dateResult);
String stringResult2=DateToString(dateResult,dateFormat);
System.out.println(" Date to string is "+stringResult2);
public static String DateToString(Date test, String dateFormat) {
String result = null;
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat);
result = myDateFormat.format(test);
//System.out.println(" reslut date is "+result);
} catch (Exception e) {
System.out.println(" Exception is "+e);
return result;
public static Date stringToDate(String strDate,String dateFormat1){
Date result1=null;
try {
DateFormat myDateFormat = new SimpleDateFormat(dateFormat1);
result1=myDateFormat.parse(strDate);
catch(Exception e){
System.out.println(" exception is "+e);
return result1;
}I am facing problem in getting the actual date. Please suggest the solution. -
Can anyone tell how to convert a String into date??
if the string is in the format "Thu Mar 25 17:11:34 GMT+05:30 2004"
i have converted it. code is
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d yyyy HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
Date date = null;
try
//date = dateFormat.parse(new Date().toString());
date = dateFormat.parse(dateLine);
catch(ParseException ex)
but i am not able to specify the year.
so when i getYear on the new Date it return 1970.@duffymo, I'm pretty sure "d" is good for a two digit date, "dd" gives you zero-padding.
The problem, presumably, is that the format string "EEE MMM d yyyy HH:mm:ss" does not match the actual format "Thu Mar 25 17:11:34 GMT+05:30 2004".
The correct format string would be "EEE MMM d HH:mm:ss z yyyy" -
Problem with the date conversion
Hi Friends,
i am facing the problem with the date conversion, Actuall my requirement is to pass the date to the screen based on the user setting roles(SU01).
I have fetched the user setting date format by using the funciton module SUSR_GET_USER_DEFAULTS, The function module picks the exact user date setting (Like as MM/DD/YYYY, MM.DD.YYYY, DD.MM.YY).
After that i have implemented the FORMAT_DATE_4_OUTPUT funciton module for converting of the user role setting date format into system date format.
for the english language case the funciton module FORMAT_DATE_4_OUTPUT works fine but the funciton module not supported for other languages
Can you please provide the Function Moudle for user setting date conversion.
The funciton module is most important for us,
Thanks
Charan
Moderator message: date conversion questions = FAQ, please search before posting.
Edited by: Thomas Zloch on Dec 21, 2010 2:19 PMHope this logic helps you.
DATA LF_DATE TYPE DATS VALUE '21122010'. " 21-dec-2010
DATA LF_DATE_BI(10).
WRITE LF_DATE TO LF_DATE_BI. "Now LF_DATE_BI contains the date in user format
"Now populate the value LF_DATE_BI to the screen field
Maybe you are looking for
-
Error while calling Strored procedure in HR Module
Hi, I have a composite which picks up a file and use that data to call API's in HR module and do some database lookups. I have done development in one instance and done with testing. So, in the same SOA instance, we want to test the composite against
-
The alignment pages look ok, have cleaned the print heads twice. Printer prints only half of every other line in document. Solutions?
-
Lumia 2520 Windows RT 8.1 Tablet unable to activat...
About a week or so ago, my Nokia Lumia 2520 tablet with Power Keyboard (purchased through Telstra in Australia) wouldn't start and took me to the Windows RT 8.1 Recovery options. After unsuccessfully trying to use the recovery options to do a refresh
-
MacBook Pro and Adobe CS and CS2
Hello fellow Mac Lovers...I am in desperate need of your help! I am a graphic designer and I am really wanting to switch over to a Mac. However, I can only afford a MacBook Pro right now plus I need the convenience. Now here is my dilemma: I was told
-
Java Kernel and the "Unlimited Strength Java Crypto Extension Policy Files"
Is Java Kernel able to download and install on-demand the "Unlimited Strength Java(TM) Cryptography Extension Policy Files"? Currently, I have to instruct the users of my applications to download those policy files from Sun's website and follow the i