首页 \ 问答 \ Java中的本地化日期格式(Localized date format in Java)

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
更新时间:2023-08-03 13:08

最满意答案

早期版本的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'
  • 有几个问题: - 文件名必须与任务名称相同( 例如 : 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 ...
  • 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' } }

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)