我想我需要使用StringFormat,但我不知道如何找出格式.
我的日期时间格式化程序有问题:
private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("dd-MM-yyyy hh:mm")
Run Code Online (Sandbox Code Playgroud)
我想要一个给定的LocalDateTime
2015-04-12T20:00
打印为
2015/12/04 20:00
但是我的时间总是打印为08:00,如何解决此问题?
我正在使用PHP解析网站上的一些数据,它给了我这种格式的时间量:
P16DT1H58M47S
Run Code Online (Sandbox Code Playgroud)
但它们并不总是有天数,如下:
PT8H10M3S
Run Code Online (Sandbox Code Playgroud)
有时候没有时间:
PT33M57S
Run Code Online (Sandbox Code Playgroud)
我需要找到的是一种将其转换为总秒数的方法.我不需要把它放到日期对象中,但我想找到一个相当快的方法来做这个,因为我有很多数据要经过.
我有一个在线表单,其中包含一些包含时间数据的字段.我将这些数据存储到MySQL数据库中的一个time字段中,该字段需要一种格式hh:mm:ss.如果用户以正确的格式输入时间,那么我想接受数据.我也想允许用户输入的标准美国时间的时候,喜欢9:30 am或11:25 pm或10:27 am等
基本上我想测试时间是否是正确的数据库格式first(hh:mm:ss),然后如果不是,测试它是否是第二个接受的格式(hh:mm am/pm),如果是,那么我将使用PHP函数strtotime()进行转换它进入数据库时间格式.如果它不是这两种格式,那么我们会显示错误消息并死掉.
有谁知道如何测试变量的值是否与这些时间格式之一匹配?
我想做的伪PHP代码:
<?php
$value = //some time;
if (is_database_time($value)){
// good no problem
}else if (is_usa_time($value)){
$value = strtotime($value);
}else{
die("error incorrect time format, try again.");
}
?>
Run Code Online (Sandbox Code Playgroud)
**编辑**
谢谢大家的帮助.我在这里使用了一些信息来创建一个完美运行的函数:
<?php
function filter_time($key,$value){
// this section handles the storage of time data
if (preg_match('/^(0?\d|1\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)){
//do nothing
}else if (preg_match('/^(0?\d|1[0-2]):[0-5]\d\s(am|pm)$/i', $value)){
$value = date( 'H:i:s', strtotime($value));
}else{
display_error('incorrect …Run Code Online (Sandbox Code Playgroud) 我想以时间格式HH:MM:SS转换十进制时间列表(HH,HHH)
16. , 16.00000381, 16.00000572, 16.00000954,
16.00001144, 16.00001335, 16.00001717, 16.00001907,
16.00002098, 16.0000248 , 16.00002861, 16.00003052,
16.00003433, 16.00003624, 16.00003815, 16.00004196,
16.00004387, 16.00004768, 16.00004959, 16.00005341
Run Code Online (Sandbox Code Playgroud)
有没有办法在python中执行此操作?
谢谢
我正在开发一个将 24 小时时间戳转换为 12 小时时间戳的程序。我设法完成转换并循环它,但我需要在检查不正确输入的输入验证中编码。错误输入的示例是:“10:83”或“1):*2”。有人可以告诉我如何使用 Exception 方法来解决这个问题吗?到目前为止,我有这个:
public class conversion {
public static void timeChange() throws Exception {
System.out.println("Enter time in 24hr format");
Scanner sc = new Scanner(System.in);
String input1 = sc.nextLine();
DateFormat df = new SimpleDateFormat("HH:mm");
DateFormat df2 = new SimpleDateFormat ("hh:mm a");
Date date = null;
String timeOutput = null;
date = df.parse(input1);
timeOutput = df2.format(date);
System.out.println("in 12 hour format: " + timeOutput);
decision();
}
public static void decision() throws Exception {
System.out.println("Would you like to enter another …Run Code Online (Sandbox Code Playgroud) 我有一个以分钟为单位的十进制值,值为3361,需要以小时为单位进行转换并以这种格式显示:56 : 01 : 00
我试过这个代码:
$scope.myTime = new Date(1970, 0, 1).setMinutes(3361);
<input type="text" class="form-control" ng-model="myTime | date:'HH:mm:ss'">
Run Code Online (Sandbox Code Playgroud)
但结果并不如我所料:08 : 01 : 00
我正在使用 I18n 本地化 Rails 应用程序,并且遇到了涉及使用 I18n 时间格式的情况。
显示的日期和时间格式如下:"Tuesday, July 11, 2017"对于 time :2017-07-11 12:30:00 +0530
为了本地化,我正在使用en.yml和es.yml两种时间格式,如下所示:
en:
time:
formats:
long: '%A, %B %d, %Y'
short: '%b %d, %Y'
Run Code Online (Sandbox Code Playgroud)
在我使用的模型中I18n.l(raw_date.to_time, format: :long),这对于英语和结果来说效果很好"Tuesday, July 11, 2017",但对于西班牙语,它的返回如下:"a, t 11, 2017"
西班牙语的日期时间格式是什么才能获得与英语相同的结果。任何帮助,将不胜感激 :)
我的网站的文章是使用.md文件编写的,为了获取这些文件的创建和修改时间我使用os.path.getctime()和os.path.getmtime()方法。
这些方法的输出如下所示:
1553541590.7233291553541590.723329虽然 HTML 需要这种格式:
2001-09-17T05:59:00+01:002013-09-16T19:08:47+01:00对于此事我有两个疑问:
谢谢。
Note : I looked as much as I could for 2 days to check if this is a duplicate. If I missed something, I apologize. This question is to find what the issue is with my attempt at a solution, not one of the existing solutions out there.
My Question
I was trying to solve some problems on hackerrank in Java 7 and I came across the time conversion problem where the problem statement is:
Problem: "Given a time in …
time-format ×10
time ×4
java ×3
datetime ×2
php ×2
python ×2
angularjs ×1
c# ×1
decimal ×1
html ×1
javascript ×1
momentjs ×1
python-3.x ×1
rails-i18n ×1
ruby ×1
testing ×1
wpf ×1