Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        4年前关闭。
                                                                                            
                
        
我正在尝试在不同的Java文本字段中显示当前时间。例如,对于秒(ss),我必须在两个单独的文本字段中拆分两个整数(ss)(例如58'在一个文本字段中将为5,在另一个文本字段中将为8)。有什么方法可以在两个不同的文本字段中分割当前时间秒?

最佳答案

如果时间是一个字符串,则可以执行以下操作:

String time = "60"; // get time from your function in some string
String textField1 = time.substring(0,0); // gets "6"
String textField2 = time.substring(1); // gets "0"


如果时间是整数,则可以执行以下操作(时间小于100):

int time = 60; // get time from your function 0-99
int textField1 = (int) time/10; // takes a number, forces it to be int after
                                // dividing by ten (ex: 65/10 = 6.5 -> 6)
int textField2 = (int) time - (textField1 * 10); // finds the first place digit
                                                 // by making it subtract the second place
                                                 // (ex: 65 - (6*10) = 5)

10-06 04:59