我希望日期格式为dd-MMM-yyyy.我的代码是:
String v_date_str="Sun Mar 06 11:28:16 IST 2011";
DateFormat formatter;
formatter = new SimpleDateFormat("dd-MMM-yyyy");
Date date_temp=null;
try {
date_temp = (Date) formatter.parse(v_date_str);
} catch (ParseException ex) {
Logger.getLogger(Attendance_Calculation.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("output: "+date_temp);
Run Code Online (Sandbox Code Playgroud)
但是,我得到的错误是:
The log message is null.
java.text.ParseException: Unparseable date: "Sun Mar 06 11:28:16 IST 2011"
at java.text.DateFormat.parse(DateFormat.java:337)
at org.fes.pis.jsf.main.Attendance_Calculation.btn_show_pending_appl_action(Attendance_Calculation.java:415)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:99)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:771)
at javax.faces.component.UICommand.broadcast(UICommand.java:372)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at …Run Code Online (Sandbox Code Playgroud) 我已经加载了我的JTree来查看我的目录结构,如我的代码和输出图像所示.这里,Tree节点默认按字母顺序排序,但我的另一个要求是我想根据目录名的第二个名称对所有节点进行排序,而不实际重命名目录.我已经在下面列出了我需要对JTree节点进行排序的名称.请给我一些建议.
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
public class FILE_NAME {
public static void main(String[] args) {
JFrame frame = new JFrame("My Jtree");
File root = new File("C:/java");
JTree tree = new JTree(new FileTreeModel(root));
frame.setSize(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(tree);
frame.setVisible(true);
}
}
class FileTreeModel implements TreeModel {
protected File root;
public FileTreeModel(File root) {
this.root = root;
}
@Override
public Object getRoot() {
return root;
}
@Override
public boolean isLeaf(Object node) {
return ((File) …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,有时给出字符值,有时给出整数值.我想得到该字符串中的位数.
例如,如果字符串包含"2485083572085748",则总位数为16.
请帮我解决一下这个.
这可能看起来很奇怪Q.
我用Java编写了一个代码(在Eclipse中).然后,我对代码做了一些修改.现在,我正在尝试运行新代码(已修改),但它仍然提供了它为前面的代码提供的输出.
我在代码中放了几个调试点,但它正在跳过一些调试点(虽然它应该停在它们上面)并在某个调试点停止,但即使在这里它也调用了前面代码中存在的方法位置(虽然我现在评论他们).它似乎从某个地方仍在调试旧代码.
如何摆脱它?
谢谢!
有人可以提供一个示例代码或至少一种方法,我可以使用它来获取JTable中多个选择的字符串值吗?我搜索了网络,但我发现了如何从单个选择中获取值的示例.基于此我尝试使用循环自己实现代码,但它在我脸上爆炸.任何帮助将不胜感激.
我有一个SSRS报告,其中包含一个包含两个嵌入表的列表.
对于这些表,如果我在每个页面上设置标题行重复,我会收到错误 "All tablix member elements in a TablixColumnHierarchy must have the RepeatOnNewPage Property set to false".
如何修复此问题并在每个页面上重复标题?
谢谢.
我有一个JButton名为button1的文本"Alter Today".
我想在这个按钮的'今天'一词的'T'下设置一个助记符(这是'今天改变'中't'或'T'的第二个例子).
当我想要做的时候:
button1.setMnemonic(6);
Run Code Online (Sandbox Code Playgroud)
我无法看到带下划线的'T'.
我在做的时候:
button1.setMnemonic('T');
Run Code Online (Sandbox Code Playgroud)
它仍然在'Alter'这个词中强调't'.
怎么做?
我遇到了以下问题:
'找到数组中出现奇数次的所有元素'.
我对此的看法是:
使用HashMap:在数组中添加值作为HashMap中的键.对应于每个键的值将是遇到键的次数.
使用O(N log N)中的快速排序对数组进行排序,然后遍历数组以检查哪些元素出现奇数次.
您怎么看?有没有其他办法解决这个问题?如果不是,那么这两种方法中的哪一种更好?
提前致谢!
为什么我们不能对Java类中的方法内声明的变量使用访问说明符?