ActiveAndroid
ActiveAndroid copied to clipboard
How to insert date in ActiveRecord !
@Column(name = "timestamp", index = true) private Date timestamp;
Or
@Column(name = "created_at") private String created_at;
Should i use String or Date .... Can i have example of how to insert date into sqlite properly ! Thankyou
ActiveAndroid supports serializing Date fields automatically. It is stored internally as a timestamp (INTEGER) in milliseconds.
@Column(name = "timestamp", index = true)
private Date timestamp;
Create a Util method to convert String to Date, if you want:
public Date getDateFromString(String selectedDate) throws ParseException{
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date date = format.parse(selectedDate);
return date;
}
ps. ActiveAndroid has a pretty strong community on Stack Overflow, so you're welcome to ask your questions there. Actually this answer is copied from the Stack Overflow.