简体   繁体   English

在Java swt的Arraylist中存储DateTime

[英]Storing DateTime in Arraylist in java swt

I'm having some problem with my program. 我的程序有问题。 I'm trying to get the values of the date from the dateTime widget from the org.eclipse.swt.widgets.DateTime . 我正在尝试从org.eclipse.swt.widgets.DateTimedateTime小部件中获取日期的值。 My program is working, when i change the date it will store in the Arraylist and print it. 我的程序正在运行,当我更改日期时,它将存储在Arraylist并打印出来。 But my problem is I don't know if it's saving or not and how can i get the values of all the date that are stored in the Arraylist? 但是我的问题是我不知道它是否正在保存,如何获取Arraylist中存储的所有日期的值?

so far this is what I tried 到目前为止,这是我尝试过的

public void readDateList()
{
    Calendar instance = Calendar.getInstance();
    instance.set(Calendar.DAY_OF_MONTH, dateFrom.getDay());
    instance.set(Calendar.MONTH, dateFrom.getMonth());
    instance.set(Calendar.YEAR, dateFrom.getYear());
    String strDateString = new SimpleDateFormat("yyyyMMdd").format(instance.getTime());

    ArrayList<String> alDate = new ArrayList<String>();
    alDate.add(strDateString);
    System.out.println(alDate);     
}

The issue is that every time you call readDateList() , the old object alDate is gone for good and you are creating a new one. 问题是,每次调用readDateList() ,旧对象alDate就会alDate消失,而您正在创建一个新对象

Remove alDate from the method readDateList and make it global to the class. 从方法readDateList删除alDate ,并将其全局readDateList该类。

ArrayList<String> alDate = new ArrayList<String>(); 

Add a new method to print the list, like: 添加新方法以打印列表,例如:

public void printList(){
    System.out.println(alDate);     
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM