简体   繁体   English

如何解析在秒内使用不正确位数的时间戳?

[英]How can I parse a timestamp that is using the incorrect number of digits for seconds?

Long story short, someone messed up a few months ago, and the Production environment is saving timestamps on certain cases, where the timestamp format as MMM-dd-yy HH:mm:sss'Z' Yes that is 3 digits for the seconds, NOT milliseconds.长话短说,几个月前有人搞砸了,生产环境在某些情况下保存时间戳,其中时间戳格式为MMM-dd-yy HH:mm:sss'Z'是的,秒数为 3 位,不是毫秒。

How can I get DateTimeFormatter to be able to parse such as a timestamp, as attempting to use that pattern above is not a valid pattern for it to use?我怎样才能让 DateTimeFormatter 能够解析时间戳等,因为尝试使用上面的模式不是它使用的有效模式?

Perhaps just use a regex to preprocess the input date before sending it to the formatter?也许只是使用正则表达式在将输入日期发送到格式化程序之前对其进行预处理?

The following regex captures all the data except for the extraneous second:以下正则表达式捕获除了无关的第二个数据之外的所有数据:

([a-zA-Z]{3})-(\d\d)-(\d\d) (\d\d):(\d\d):\d(\d\d)(.*)

And this replacement string puts it back together:这个替换字符串将它重新组合在一起:

$1-$2-$3 $4:$5:$6$7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java中解析BSON时间戳 - How can i parse BSON Timestamp in java 如何为数字的数字数组(int)分配内存,其长度等于该数字的位数? - How can I allocate memory for an array of digits (int) of a number with the length being equal to the number of digits of that number? 如何在Java中使用正则表达式解析字符串的最后6位数字? - How do I parse the last 6 digits of a string using regex in Java? 如何使用Java中的字符串或列表检查数字的位数是升序还是降序? - How can I check if the digits of a number are ordered ascending or descending whitout using strings or lists in Java? 如何使用for循环交换Java中数字的第一个和最后一个数字? - How can I swap the first and last digits of a number in Java using for for-loops? 如何按数字的位数对列表中的数字进行分组 - How can I group numbers in a list by their number of digits 如何屏蔽字符串的前4位数字 - How can I mask the first 4 digits of a stringed number 如何解析Java中看似标准的时间戳? - How can I parse a seemingly standard Timestamp in Java? 如何使用 Java 以最优化的方式在大型排序文件中搜索特定数字/时间戳? - How can I search for a specific number/timestamp in a large sorted file in most optimized way using Java? 解析小于 6 位的纳秒 - Parse nano seconds with less than 6 digits
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM