Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to convert Date(ActionScript 3) to java.util.Date through a xml.

First, write a user defined ActionScript class like this.

public class User
{
    public function User()
    {
        userDate = new Date();
    }

    public var id:String = null;
    public var password:String = null;
    public var userDate:Date = null;

}

Second, create its instance and set each of values, so it converts ActionScript class to a xml for using XMLEncoder having its schema file.

This is the result xml, and send this xml to a server for using a HTTPService.

<User>
  <id>system</id>
  <password>manager</password>
  <userDate>Fri Jan 14 09:02:17 GMT+0900 2011</userDate>
</User>

Finally, In server side of Java, I want to convert this xml to Java class like this for using JAXB Unmarshaller.

public class User {

    public User() {
    }

    private String id;
    private String password;
    private Date userDate;


    public void setId(String id) {
        this.id = id;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public void setUserDate(Date userDate) {
        this.userDate = userDate;
    }
    public String getId() {
        return id;
    }
    public String getPassword() {
        return password;
    }
    public Date getUserDate() {
        return userDate;
    }

}

But, as a result, "UserDate" property is only going to be null...

Why "UserDate" property is null ? And, please tell me solutions if any.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

The text representation of your Flash Date and java.util.Date are probably not compatible. Since both date objects are internally based on the number of milliseconds since January 1, 1970, I would recommend using date.time in AS3 to get the integer value of the date, sending it to Java, and then using date.setTime() to set the correct date.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...