Android 获取日期并插入到文件名
我有一个非常烦人的问题。我想获取当前日期/时间并将其插入文件名中,但我一生都无法让它工作。
我想获取 2011-11-18 12:13:57 的时间,然后将其插入到我的文件名
filename-2011-11-18-12:13:57.tar.gz
我已经尝试过 SimpleDateFormat 等,但它就是行不通!
(我正在用 Eclipse Indigo 编写)
I am having a quite annoying problem. I want to get the current date/time and insert it into a filename but I can't for my life get it to work.
I want to get the time as 2011-11-18 12:13:57 and then insert it into my filename
filename-2011-11-18-12:13:57.tar.gz
I have tried SimpleDateFormat
etc. but it just won't work!
(I am writing in Eclipse Indigo)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用这个:
此外,您一定在某个地方遇到错误,这对查找问题有很大帮助。确保没有空的
catch
块:You can use this:
Also you must be getting an error somewhere, that would help a lot to find the problem. Make sure you don't have empty
catch
blocks :使用它来获取您想要的日期时间:
您可以像这样创建文件:
Use this to get the date time you want :
and you can create your file like this :
我希望这可以帮助您获取当前日期和时间
如何使用 SimpleDateFormat 显示当前日期?
I hope this could help u out to get the current date and time
How to use SimpleDateFormat to show the current Date?