本文介绍了javafx中的日期显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用javafx开发应用程序.我正在使用SQLITE作为数据库.
我正在从数据库中获取记录并显示日期.
如果数据库中有任何日期,则显示1970-01-01.
可以帮助我显示正确的日期.
[从评论中添加]
是的
我有Java类,正在检索列表
像这样
i am developing an application in javafx. i am using SQLITE as database.
i am fetching records from db and displaying date.
it is displaying 1970-01-01 if there is any date is present in databse.
can some help me to display correct date.
[Added from comment]
yeah
i have java class in that i am retrieving list
like this
public static Goal[] selectCompletedGoals(int goalType, int userID)
{
System.out.println("I am in selectCompletedGoals");
int varResult=0;
Statement stmt=null;
ResultSet rs;
String query;
ArrayList results = new ArrayList();
Goal goal=new Goal();
Vector goalsVect = new Vector();
try
{
Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:EvolutionUniversity_Offline.db","EvolutionUniversity_Offline","");
stmt = con.createStatement();
// Database db = new Database();
//con = db.getConnection();
query = "select * from Goal where GoalType="+goalType+" and UserID="+userID+" and GoalStatus=1 ";
System.out.println("Querin in selectCompletedGoals is " + query);
//stmt = con.createStatement();
rs = stmt.executeQuery(query);
System.out.println("result set in selectCompletedGoals is " + rs);
System.out.println("result set count in selectCompletedGoals is " + rs.getRow());
// if(rs.getRow()>0)
// {
while(rs.next())
{
System.out.println("Completed date in goals1 " + rs.getDate("completedDate"));
goal = extractGoalsData(rs);
goalsVect.add(goal);
}
//}
}
catch(Exception ex)
{
System.out.println("Exception: "+ex);
try{
stmt.close();
con.close();
}catch (SQLException ex1){
System.out.println(ex1 );
}
}
finally
{
try {
stmt.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(GoalsService.class.getName()).log(Level.SEVERE, null, ex);
}
}
Goal[] goalList = new Goal[goalsVect.size()];
goalsVect.toArray(goalList);
return goalList;
}
private static Goal extractGoalsData(ResultSet rs) throws Exception
{
Goal goal = new Goal();
goal.goalID = rs.getInt("GoalID");
goal.userID = rs.getInt("UserID");
goal.goalTitle = rs.getString("GoalTitle");
goal.goalDescription=rs.getString("GoalDescription");
goal.createdDate = rs.getDate("CreatedDate");
goal.lastModifiedDate = rs.getDate("LastModifiedDate");
goal.completedDate = rs.getDate("CompletedDate");
System.out.println("Completed date in goals " + rs.getDate("CompletedDate"));
//goal.goalKudos = rs.getInt("GoalKudos");
goal.goalStatus=rs.getInt("GoalStatus");
goal.goalsType = rs.getInt("GoalType");
goal.blogID = rs.getInt("BlogID");
return goal;
}
and displaying in front end like this
goalsList = GoalsService.selectCompletedGoals(goalType, userID);
var todaysDate:String;
//goalDate.add(Calendar.DATE,1);
var year:String;
var month:String;
var day:String;
todaysDate = "{goalDate.get(Calendar.YEAR)}-{goalDate.get(Calendar.MONTH)}-{goalDate.get(Calendar.DATE)}";
//journalDateText.text= dateString;
//println("Goal Completed Date {goalsList[i].completedDate}");
if(goalsList[i].completedDate.equals(""))
{
todaysDate=todaysDate;
println("Goal Completed Date {todaysDate}");
}
else
{
todaysDate=goalsList[i].lastModifiedDate.toString();
println("Goal Completed Date {goalsList[i].lastModifiedDate.toString()}");
}
insert HBox{
layoutY:40
layoutX:20
spacing:10
translateY: bind (sceneBucketList.height - container_height) / 2 - 120;
content:
[
bucketListTextBox[i]=TextBox
{
width:bind 150
text:goalsList[i].goalTitle
id:"bucketlistTextBox{i}"
},
bucketListCheckBox[i]= CheckBox
{
translateX:0
id:"bucketlistCheckBox{i}"
selected:status
},
bucketListLabel[i]= Label
{
translateX:50
id:"bucketlistLabel{i}"
//text:goalsList[i].completedDate.toString()
text:todaysDate
},
bucketListText[i]= Text
{
id:"bucketlistText{i}"
content:"{goalsList[i].goalID}"
visible:false
}
]
} into listElements.content;
推荐答案
这篇关于javafx中的日期显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!