Data Type Conversions
1. String to Int
Solution A:
int x =Integer.parseInt("9");
Solution B:
String num = "9";
Integer res = Integer.valueof(num);
Integer res = Integer.valueof(num);
2. Int to String
int a = 9;
String Value = a.to_string();
3. Date Formatting
If date format is 2017-08-07 then we can change it to any format(eg:dd-MMM-yyyy HH:mm:ss)
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
try {
Date dt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(assmovedate);
System.out.println("date captured!!!!"+dt);
Date dt1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(assreturningdate);
System.out.println("date captured!!!!"+dt1);
System.out.println(formatter.format(dt));
System.out.println(formatter.format(dt1));
String assetmovedate = (String)formatter.format(dt); // Asset Move date converted to date format
System.out.println("new date format" +assetmovedate);
String assetreturningdate = (String)formatter.format(dt1); // Asset returning date converted to date format
System.out.println("new date format 1" +assetreturningdate);
}
catch (ParseException e)
{
e.printStackTrace();
}
0 Comments