我有两行要打印在主应用程序屏幕上。我试图将它们设置为等于要在主屏幕上打印的变量。我放入Java文件的内容是:

public class TimeZoneConverter {

            public void main(String args[]) {

             //Date will return local time in Java
             Date localTime = new Date();

             //creating DateFormat for converting time from local timezone to GMT
             SimpleDateFormat converter = new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss");

             //getting GMT timezone, you can get any timezone e.g. UTC
             converter.setTimeZone(TimeZone.getTimeZone("GMT"));

             String1 = System.out.println("local time : " + localTime);;
             String2 = System.out.println("time in GMT : " + converter.format(localTime));

            }
        }

}


它说字符串不能解析为变量。我将如何尝试将其显示在主屏幕上?

最佳答案

我试图将它们设置为等于要在主屏幕上打印的变量。


这是将它们提取为变量的方式。

String localTimeStr = "local time : " + localTime;
String gmtStr = "time in GMT : " + converter.format(localTime);
System.out.println(localTimeStr);
System.out.println(gmtStr);


System.out.println()返回一个空值。您不能将其分配给任何东西。

[编辑]

由于您要在Android屏幕上进行打印,因此请使用Toast或找到文本视图和set it's text

10-04 15:01
查看更多