How to convert a date in own format in Android [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my JSON response i am getting date like this [1987,8,22], but I have to display the date like 22-08-1987. Can anyone tell me how to convert this.
Thanks in advance.

Use the org.json package to parse the JSON into a JSONArray (if your haven't already done so). Then you can instantiate a GregorianCalendar using the three elements of the array accessible through JSONArray.getInt. This date then can be formatted as any other Java date object.

You can try this::
String date = "1987,8,22";
String[] part = date.split(",");
date = part[2]+"-"+part[1]+"-"+part[0];
Hope it Helps!!

Related

JSON Object java to long [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 months ago.
Improve this question
i have a json object and want to convert it to an int, but i get different numbers. On the first get the output is 1665750692735 (the right One), but on the getInt the output -696618113. Why?
Ok its because its an long. But how i get the long from the JSON Object?
JSON;
{"date":1665750692735,"name":"testDateTwo"}
Method:
public void add(JsonObject date) {
System.out.println((date.get("date")));
System.out.println((date.getInt("date")));
}
because the maximum value of an int is 2147483647,When long converts int, a data overflow occurs

replace x, y in arraylist of arraylists in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to figure out how to replace a specific index in a arraylist of arraylists
The only stuff I've been able to find so far is how to just get the index with .get(x).get(y)
I'm having no real luck with google at the moment, so I figured I'd finally make a post about it. Any help would be great, thanks in advance.
You can do
.get(x).set(y, value);
Something like this:
ArrayList<ArrayList<String>> s = . . .;
s.get(3).set(4, "new value");
As #peeskillet suggest a best solution..
But check this core java code if it have some sense.
String arrayList[] = {....your array content...};
for (String token : arrayList) {
token = token.replace("x", "replaceanythings");
token = token.replace("y", "replaceanythings");
}

Convert IBM JMSMessageId to String in JAVA [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am receiving following sting in properties from IBM MQ as message Id, I want to convert it back to original value in string or integer. Please help me do that.
JMSMessageID=ID:c1d4d840d8e4c16dd4d8404040404040520b91682005a90d
What you see after JMSMessageID=ID i.e. c1d4d840d8e4c16dd4d8404040404040520b91682005a90d is the real (or original) message id. It is 24 byte long. You can't convert that into an integer.

Parsing using Jsoup [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I ma new to java.
I have a string s:
s="<name>header</name><content>Good Morning</content>"
How to get value of content and name using Jsoup?
What JSoup returns when content is empty?null?
You can use jsoup:
Connection con2=Jsoup.connect(url);
Document doc = con2.get();
//or use Document doc = Jsoup.parse(html);
Element e=doc.head().select("meta[name=header]").first();
String url=e.attr("content");
http://jsoup.org/cookbook/extracting-data/attributes-text-html
http://jsoup.org/cookbook/extracting-data/selector-syntax
For your edit I do agree with the answer that #Hein give you.
Use this RegEx for example: name=(.*) content=(.*) \/>. The name will be in the first group and the content in the second.
I would recommend double quotes around the strings though. In that case you can use this regex: name=\"(.*)\" content=\"(.*)\"
Edit after the OPs edit:
If you have complete control of the data yourself you should consider saving the name and content in seperate columns in your database, or look into serialization maybe.

Is it possible to use a String as the arguments for Files.move(source,target..) in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Can you use strings in some way to define the source and target of files.move.
Heres the documentation http://docs.oracle.com/javase/tutorial/essential/io/move.html
According to the javadoc, you can not use strings as arguments for Files.move .
What seems to be a better solution for you, is using the rename method on File. Something like this:
File file = new File("/path/to/file/to/be/moved");
boolean moved = file.renameTo("/new/path/for/the/file");
if(!moved)
//Handle the error
Short answer is no: Files.move requires Path objects. That said, you can use Paths.get(str) to simply turn a String into a Path.

Categories

Resources