Java中的本地化日期格式(Localized date format in Java)
我在millis中有一个时间戳,并且想要用分钟精度来表示日期,月份,年份和小时的格式。
我知道我可以指定这样的格式:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yy HH:mm"); String formatted = simpleDateFormat.format(900000)
但是我希望格式能够以用户的语言环境进行本地化。 我也试过了
DateFormat DATE_FORMAT = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); DATE_FORMAT.format(new Date());
但它不显示小时。 我该怎么做?
I have a timestamp in millis and want to format it indicating day, month, year and the hour with minutes precission.
I know I can specify the format like this:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yy HH:mm"); String formatted = simpleDateFormat.format(900000)
But I'd like the format to be localized with the user's locale. I've also tried
DateFormat DATE_FORMAT = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()); DATE_FORMAT.format(new Date());
But it does not show the hour. How can I do it?
原文:https://stackoverflow.com/questions/17853150
最满意答案
早期版本的Gruntjs包含一些默认任务,如concat和min。 从Grunt 0.4开始,你必须添加你想要的所有任务(插件)。 我相信对于缩小和串联你可以使用像grunt-contrib-uglify这样的任务。
请确保您正在运行最新版本的Grunt。 许多在线可用教程提到Grunt 0.3,但自那以后发生了很多变化。 例如,提到grunt.js(Grunt 0.3)而不是Gruntfile.js(0.4)的教程在很多方面已经过时。
Older versions of Gruntjs contained some default tasks, like concat and min. Starting with Grunt 0.4 you have to add all the tasks (plugins) you want yourself. I believe that for both minification and concatenation you can use a task like grunt-contrib-uglify.
Please make sure you're running the latest version of Grunt. A lot of online available tutorials mention Grunt 0.3, but a lot has changed since then. For example, tutorials mentioning grunt.js (Grunt 0.3) instead of Gruntfile.js (0.4) are obsolete in a lot of ways.
相关问答
更多-
弄清楚了: //Does not work dest : ['build/index.html'] 作为字符串工作,但不是数组: //Works dest : 'build/index.html' Figured it out: //Does not work dest : ['build/index.html'] Works as a string, but not an array: //Works dest : 'build/index.html'
-
使用grunt找不到任务(Task not found using grunt)[2023-09-12]
有几个问题: - 文件名必须与任务名称相同( 例如 : ngAnnotate.js - > task: ngAnnotate ) - 您的任务不是由grunt插件分组的 - 共享配置任务和注册任务的名称,然后您无法设置home配置任务和home注册任务,因为当您使用grunt home调用它时,grunt无法知道您正在引用的任务。 您必须遵守配置任务的此规则: 在一个文件中使用相同插件的组配置任务,不要在配置任务中混合使用grunt-plugins,注册任务适用于此作业。 你当前的配置问题,要调用cssmi ... -
问题是由于我使用NodeJS版本0.1而项目最初是在具有NodeJS v5的服务器上构建的。 因此,npm没有所有正确的grunt依赖。 我在受影响的服务器上以root用户身份执行了以下操作 apt-get purge nodejs apt-get purge npm apt-get autoremove // remove any orphan dependences 一旦我摆脱了一切,我按照nodejs网站使用以下命令安装NodeJS的第6版: curl -sL https://deb.nodesou ...
-
我今天早上遇到这个问题。 我在Bootstrap的package.json文件中改变了第30行:从“〜0.4.2”到“0.4.2”: 27 "devDependencies": { ... 30 "grunt" : "0.4.2" 这意味着0.4.3不再符合依赖规范,但这也意味着您以后不会安装新版本的grunt。 这足以使事情工作,但你应该可以最终改变它(也许在你的下一个引导项目离开它)。 I ran into this problem this morning too. I ended up c ...
-
找不到任务“jshint”(Task “jshint” not found)[2022-05-22]
Gruntfile.js的第1行应该是module.exports = function(grunt) {而不是module.exports = funtion(grunt) { 没有看到函数声明可以抛出Syntax Error: Unexpected token您尝试运行任务时收到的Syntax Error: Unexpected token行。 Line 1 of the Gruntfile.js should be module.exports = function(grunt) { rather t ... -
好的,我通过将--verbose标志传递给grunt build命令来找出解决方案。 问题是有两个bower_components ,一个在我当前的目录(。)中,另一个在./app目录下,因为我的usemin块build:js({app,.})正在读取这两个位置,即. 和./app ,所以Grunt的concat任务是复制所有文件。 Reading ./bower_components/angular/angular.js...OK Reading app/bower_components/angular/ ...
-
早期版本的Gruntjs包含一些默认任务,如concat和min。 从Grunt 0.4开始,你必须添加你想要的所有任务(插件)。 我相信对于缩小和串联你可以使用像grunt-contrib-uglify这样的任务。 请确保您正在运行最新版本的Grunt。 许多在线可用教程提到Grunt 0.3,但自那以后发生了很多变化。 例如,提到grunt.js(Grunt 0.3)而不是Gruntfile.js(0.4)的教程在很多方面已经过时。 Older versions of Gruntjs contained ...
-
您的sass任务嵌套在concat ,这就是为什么它无法识别sass任务并返回找到的No "sass" targets found. 错误。 取消你的sass任务: grunt.initConfig({ concat: { ... }, sass: { dist: { files: [{ src: 'css/sass/styles.scss', dest: 'css/styles.css' }] } }, }); ...
-
我只需要使用grunt-assemble $ npm install grunt-assemble --save-dev 并在Gruntfile.js中调整这一行 grunt.loadNpmTasks('grunt-assemble'); I just had to use grunt-assemble $ npm install grunt-assemble --save-dev And adjust this line in the Gruntfile.js grunt.loadNpmTasks( ...
-
这应该工作: concat: { js: { src: [ 'app/**/*.js', '!**/*test.js' ], dest: 'app/scripts.js' } } This should work: concat: { js: { src: [ 'app/**/*.js', '!**/*test.js' ], dest: 'app/scripts.js' } }