数据库(SQLite)有一个REAL类型的字段,其中包含表单的值(42153.659595)。 如何在表格中转换这个值" dd.MM.yy HH:mm:ss"如果42153.659595 = 29.05.2015 15:49:49?
答案 0 :(得分:1)
您可以明确说明您需要哪种日历系统:http://www.sqlite.org/lang_datefunc.html
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class SSCCE extends Application {
private Stage primaryStage;
private AnchorPane rootLayout;
private TreeView<Wrapper> overview;
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("SSCCE");
initRootLayout();
showTreeView();
}
public void initRootLayout() {
rootLayout = new AnchorPane();
rootLayout.setPrefSize(300, 200);
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
}
ObservableList<String> columns = FXCollections.observableArrayList();
ObservableList<ObservableList<String>> data = FXCollections.observableArrayList();
ObservableList<Wrapper> items = FXCollections.observableArrayList();
private void showTreeView() {
// Dummy values
columns.addAll("key", "text");
data.add(FXCollections.observableArrayList("1", "test"));
data.add(FXCollections.observableArrayList("1", "test2"));
data.add(FXCollections.observableArrayList("2", "test3"));
data.add(FXCollections.observableArrayList("2", "test4"));
data.add(FXCollections.observableArrayList("3", "test5"));
data.add(FXCollections.observableArrayList("3", "test6"));
data.add(FXCollections.observableArrayList("4", "test7"));
data.add(FXCollections.observableArrayList("4", "test8"));
data.add(FXCollections.observableArrayList("5", "test9"));
data.add(FXCollections.observableArrayList("5", "test10"));
data.add(FXCollections.observableArrayList("6", "test11"));
data.add(FXCollections.observableArrayList("6", "test12"));
items.addAll(new Wrapper(1, "wrapper 1"), new Wrapper(2, "wrapper 2"), new Wrapper(3, "wrapper 3"), new Wrapper(4, "wrapper 4"), new Wrapper(5, "wrapper 5"), new Wrapper(6, "wrapper 6"));
TreeItem<Wrapper> root = new TreeItem<Wrapper>();
overview = new TreeView<Wrapper>(root);
overview.setPrefHeight(75);
overview.setCellFactory(new Callback<TreeView<Wrapper>, TreeCell<Wrapper>>() {
@Override
public TreeCell<Wrapper> call(TreeView<Wrapper> stringTreeView) {
TreeCell<Wrapper> treeCell = new TreeCell<Wrapper>() {
@Override
protected void updateItem(Wrapper item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
if (getTreeItem().isLeaf() && isSelected()) {
setText(null);
// A debug text that proves that the wrong item is being selected.
System.out.println("Selected wrapper: " + item);
TableView<ObservableList<String>> table = new TableView<ObservableList<String>>();
for (int i = 0; i < columns.size(); i++) {
final int j = i;
TableColumn<ObservableList<String>, String> column = new TableColumn<ObservableList<String>, String>(
columns.get(i));
column.setCellValueFactory((
TableColumn.CellDataFeatures<ObservableList<String>, String> param) -> new SimpleStringProperty(
param.getValue().get(j)
.toString()));
table.getColumns()
.add(column);
}
ObservableList<ObservableList<String>> selected_data = FXCollections
.observableArrayList();
for(int i = 0; i < data.size(); i++) {
if(Integer.parseInt(data.get(i).get(0)) == item.getKey()) {
selected_data.add(data.get(i));
}
}
table.setItems(selected_data);
VBox vbox = new VBox(new Label(item
.getValue()), table);
setGraphic(vbox);
} else {
setText(item.getValue());
setGraphic(null);
}
}
}
};
return treeCell;
}
});
for (int i = 0; i < items.size(); i++) {
TreeItem<Wrapper> target = new TreeItem<Wrapper>(items.get(i));
root.getChildren().add(target);
}
overview.setShowRoot(false);
rootLayout.getChildren().add(overview);
}
public static void main(String[] args) {
launch(args);
}
}
class Wrapper {
private int key;
private String value;
Wrapper(int key, String value) {
this.key = key;
this.value = value;
}
int getKey() {
return key;
}
String getValue() {
return value;
}
public String toString() {
return "Wrapper " + key;
}
}
原则上只是不“解析”(你的意思是:解释原始表示)。使用Sqlite API /内置SQL函数为您完成
为了信息的利益:
答案 1 :(得分:0)
使用API /内置SQL函数( 42153.659595 - 数据库中的值)实现正确的值:
SELECT datetime(julianday(42153.659595, 'localtime') + 2415018.29167) AS DT;
输出:
DT |
2015-05-29 15:49:49|
手动选择常量 2415018.29167 并查询:
SELECT datetime (2415018.29167);
返回当前的格林威治标准时间。
我使用第三方应用程序并且缺少有关数据库的文档。也许这个奇怪的决定,但它确实有效。谢谢大家的答案。