GVKun编程网logo

带有夏时制的时间戳计算(夏时制换算)

18

本文将分享带有夏时制的时间戳计算的详细内容,并且还将对夏时制换算进行详尽解释,此外,我们还将为大家带来关于Android进阶之使用时间戳计算时间差、iOS根据时间戳计算聊天列表的时间(上午/下午)、j

本文将分享带有夏时制的时间戳计算的详细内容,并且还将对夏时制换算进行详尽解释,此外,我们还将为大家带来关于Android进阶之使用时间戳计算时间差、iOS 根据时间戳计算聊天列表的时间(上午/下午)、java12小时制的时间转换为24小时制、Javascript的时间戳和php的时间戳转换注意事项的相关知识,希望对你有所帮助。

本文目录一览:

带有夏时制的时间戳计算(夏时制换算)

带有夏时制的时间戳计算(夏时制换算)

中欧夏令时开始于三月的最后一个星期日。我们将时钟设置为02:00到03:00。如果我在数据库请求中进行时间戳计算会发生什么?比方说,在01:59?

UPDATE sessions SET aliveuntil = (CURRENT_TIMESTAMP + INTERVAL ''1'' MINUTE) WHERE id = ?

结果是03:00还是02:00?

如果我们将时钟设置为03:00到02:00,那结束了呢?

SELECT id FROM sessions WHERE aliveuntil < (CURRENT_TIMESTAMP - INTERVAL ''1'' MINUTE)

时间从03:00更改为02:00之后…(CURRENT_TIMESTAMP - INTERVAL ''1''MINUTE)在02:00会发生什么?是02:59还是01:59?

应该如何处理?最佳实践以及Oracle Database 11g 11.2.0.2.0版如何处理(在我的特定情况下)?

答案1

小编典典

如果我正确地理解了他们的文档,则取决于如何在数据库中设置表/列。如果将这些列设置为使用WITH TIME
ZONE,则Oracle自动确定正确/相关的值。在上面的示例中,如果aliveuntil列具有此设置,那么如果您尝试在1:59处添加1分钟,则时间将更新为3:00。

这是我找到的有关该主题的有用文章:

http://docs.oracle.com/cd/B19306_01/server.102/b14225/ch4datetime.htm

向下滚动到文章底部,您应该看到所要查找的内容。

这是我发现相关的文章部分:

例如,在美国东部地区,夏令时生效时,时间从01:59:59 am更改为3:00:00 am。02:00:00和02:59:59
am之间的时间间隔不存在。该时间间隔中的值无效。

Android进阶之使用时间戳计算时间差

Android进阶之使用时间戳计算时间差

本文实例为大家分享了Android使用时间戳计算时间差的具体代码,供大家参考,具体内容如下

因当前项目需要计算时间差,进行数据处理,所以在Csdn上找了一下,之后修修补补是可以用的,建议大家如果用到项目中的话,可能需要把老的时间戳或者时间format存储在文件或者sp中,之后用于判断,然后进行自己的逻辑处理。

Effect :

Log执行:

注:这个可以自己简单封装下,比较简单。

MainActivity :

package com.bakheet.effect.time;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity {

 private SimpleDateFormat format;
 public String oldtime ;
 public String newtime;
 private TextView mContent;
 private TextView mCount;
 private TextView mBtnNow;
 private TextView mBtn;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  mBtn = (TextView) findViewById(R.id.btn);
  mBtnNow = (TextView) findViewById(R.id.btn_Now);
  mCount = (TextView) findViewById(R.id.count);
  mContent = (TextView) findViewById(R.id.content);

  //Csdn内一篇博主的博文
  mBtn.setonClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {
    Toast.makeText(MainActivity.this,"Csdn博友事件触发",Toast.LENGTH_SHORT).show();
    try {
    Date d1 = format.parse("2012-11-05 12:00:00");//后的时间
    Date d2 = format.parse("2012-11-04 11:10:00"); //前的时间
    Long diff = d1.getTime() - d2.getTime(); //两时间差,精确到毫秒

    Long day = diff / (1000 * 60 * 60 * 24);   //以天数为单位取整
    Long hour=(diff/(60*60*1000)-day*24);    //以小时为单位取整
    Long min=((diff/(60*1000))-day*24*60-hour*60); //以分钟为单位取整
    Long second=(diff/1000-day*24*60*60-hour*60*60-min*60);//秒

     Log.e("tag","day =" +day);
     Log.e("tag","hour =" +hour);
     Log.e("tag","min =" +min);
     Log.e("tag","second =" +second);

     mContent.setText("day = "+day+",hour = "+hour+",min = "+min+",second = "+second);
    } catch (Exception e) {
     e.printstacktrace();
    }
   }
  });

  //获取当前的时间戳和时间转译 - 这里同时用存储老的时间
  mBtnNow.setonClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {
    Toast.makeText(MainActivity.this,"获取当前时间",Toast.LENGTH_SHORT).show();
    long timeMillis = System.currentTimeMillis();
    Log.e("tag timeMillis =",""+timeMillis);
    //将时间戳转为日期格式
    String time = stampToDate(timeMillis);
    Log.e("tag time = ",time);
    oldtime=time;
    Log.e("tag newtime = ",oldtime);
    try {
     //将日期格式转回为时间戳的格式
     String what = datetoStamp(time);
     Log.e("tag what = ",what);
    } catch (ParseException e) {
     e.printstacktrace();
    }

   }
  });

  //This is my code - - 主要作用与计算时间差 (会用到之前我们的记录的时间,所以使用的时候,无比先执行上面的逻辑)
  mCount.setonClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View view) {
    //思维方式,使用最新的时间减去之前我们的老时间进行运算

    Toast.makeText(MainActivity.this,"新老时间触发",""+timeMillis);
    String time = stampToDate(timeMillis);
    Log.e("tag time = ",time);
    newtime=time;
    Log.e("tag newtime = ",newtime);
    try {
    //严格来讲,在使用中这里需要判断的,尤其是null的判断,这里我们使用的了 try catch

    Date d1 = format.parse(newtime); //当前时间
    Date d2 = format.parse(oldtime); //之前记录的时间

    Long diff = d1.getTime() - d2.getTime(); //两时间差,精确到毫秒
     //以天数为单位取整
     Long day = diff / (1000 * 60 * 60 * 24);
     //以小时为单位取整
     Long hour=(diff/(60*60*1000)-day*24);
     //以分钟为单位取整
     Long min=((diff/(60*1000))-day*24*60-hour*60);
     //以秒为单位
     Long second=(diff/1000-day*24*60*60-hour*60*60-min*60);

     Log.e("tag","second =" +second);
     mContent.setText("day = "+day+",hour = "+hour+",min = "+min+",second = "+second);
    } catch (Exception e) {
     //建议抛出总异常
     e.printstacktrace();
    }
   }
  });
 }


  /**
  * 将时间转换为时间戳
  */
 public String datetoStamp(String time) throws ParseException {
  SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  Date date = simpleDateFormat.parse(time);
  long ts = date.getTime();
  return String.valueOf(ts);
 }

  /**
  * 将时间戳转换为时间
  */
 public String stampToDate(long timeMillis){
  SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  Date date = new Date(timeMillis);
  return simpleDateFormat.format(date);
 }
}

MainActivity Xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.bakheet.effect.time.MainActivity">

 <TextView
  android:layout_marginTop="10dp"
  android:layout_width="match_parent"
  android:padding="5dp"
  android:layout_height="wrap_content"
  android:text="csdn博友时间差算法"
  android:gravity="center"
  android:id="@+id/btn"
  />

 <TextView
  android:layout_marginTop="10dp"
  android:layout_width="match_parent"
  android:padding="5dp"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:text="当前时间"
  android:id="@+id/btn_Now"
  />

 <TextView
  android:layout_marginTop="10dp"
  android:layout_width="match_parent"
  android:padding="5dp"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:id="@+id/count"
  android:text="新老时间计算"
  />
 <TextView
  android:layout_marginTop="10dp"
  android:layout_width="match_parent"
  android:padding="5dp"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:id="@+id/content"
  android:text=""
  />
</LinearLayout>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

iOS 根据时间戳计算聊天列表的时间(上午/下午)

iOS 根据时间戳计算聊天列表的时间(上午/下午)

把时间戳转成聊天时间(上午 10:00  、  昨天 14:00 、 3月15日 15:00)

+(NSString*)ChatingTime:(NSString *)timestring{
  
    
    int timestamp=  [timestring intValue];
    
    
        // 创建日历对象
        NSCalendar *calendar = [NSCalendar currentCalendar];
        
        // 获取当前时间
    NSDate *currentDate = [NSDate date];
        
        // 获取当前时间的年、月、日。利用日历
        NSDateComponents *components = [calendar components:NSCalendarUnitYear| NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate];
        NSInteger currentYear = components.year;
        NSInteger currentMonth = components.month;
        NSInteger currentDay = components.day;
    
        
        // 获取消息发送时间的年、月、日
        NSDate *msgDate = [NSDate dateWithTimeIntervalSince1970:timestamp];
        components = [calendar components:NSCalendarUnitYear| NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:msgDate];
        CGFloat msgYear = components.year;
        CGFloat msgMonth = components.month;
        CGFloat msgDay = components.day;
        CGFloat msghours = components.hour;
        // 进行判断
        NSDateFormatter *dateFmt = [[NSDateFormatter alloc] init];
        if (currentYear == msgYear && currentMonth == msgMonth && currentDay == msgDay) {
            //今天
            if (msghours<12) {
                dateFmt.dateFormat = @"上午 hh:mm";
            }else{
                dateFmt.dateFormat = @"下午 hh:mm";
            }
           
        }else if (currentYear == msgYear && currentMonth == msgMonth && currentDay-1 == msgDay ){
            //昨天
            dateFmt.dateFormat = @"昨天 HH:mm";
        }else{
            //昨天以前
            dateFmt.dateFormat = @"MM-dd HH:mm";
        }
        // 返回处理后的结果
        return [dateFmt stringFromDate:msgDate];
    
}

 

java12小时制的时间转换为24小时制

java12小时制的时间转换为24小时制

import java.text.SimpleDateFormat;
import java.util.Date;
 
public class ceshi {
    public static void main(String[] args) {
        SimpleDateFormat objSDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");//转换为24小时制
        String strCurrentTime = objSDateFormat.format(new Date());
        System.out.println(strCurrentTime);
    }
 
}

大写的HH为24小时制,小写的hh为12小时制。

在ss的后面加上 a,这样可以在后面显示上下午:显示效果为“2019-03-24 17:00:14 下午”

Javascript的时间戳和php的时间戳转换注意事项

Javascript的时间戳和php的时间戳转换注意事项

这里要注意的是js的时间戳是13位,php的时间戳是10位,转换函数如下:
复制代码 代码如下:

var nowtime = (new Date).getTime();/*当前时间戳*/
/*转换时间,计算差值*/
function comptime(beginTime,endTime){
var secondNum = parseInt((endTime-beginTime*1000)/1000);//计算时间戳差值
if(secondNum>=0&&secondNum<60){
return secondNum+''秒前'';
}
else if (secondNum>=60&&secondNum<3600){
var nTime=parseInt(secondNum/60);
return nTime+''分钟前'';
}
else if (secondNum>=3600&&secondNum<3600*24){
var nTime=parseInt(secondNum/3600);
return nTime+''小时前'';
}
else{
var nTime = parseInt(secondNum/86400);
return nTime+''天前'';
}
}
t = comptime("1324362556",nowtime);//timestamp为PHP通过ajax回传的时间戳
alert(t);
您可能感兴趣的文章:
  • php日期转时间戳,指定日期转换成时间戳
  • PHP 时间转换Unix时间戳代码
  • PHP中UNIX时间戳和日期间的转换与计算实例
  • 解析php时间戳与日期的转换
  • 时间戳与时间相互转换(php .net精确到毫秒)
  • PHP时间戳与日期之间转换的实例介绍
  • php时间戳转换的示例
  • php强大的时间转换函数strtotime
  • php实现兼容2038年后Unix时间戳转换函数
  • PHP入门教程之日期与时间操作技巧总结(格式化,验证,获取,转换,计算等)
  • php把时间戳转换成多少时间之前函数的实例
  • php自定义时间转换函数示例

今天的关于带有夏时制的时间戳计算夏时制换算的分享已经结束,谢谢您的关注,如果想了解更多关于Android进阶之使用时间戳计算时间差、iOS 根据时间戳计算聊天列表的时间(上午/下午)、java12小时制的时间转换为24小时制、Javascript的时间戳和php的时间戳转换注意事项的相关知识,请在本站进行查询。

本文标签:

上一篇Windows 10:通过 LPE 漏洞通过 Razer 鼠标获得管理员(razer鼠标驱动)

下一篇如何使用MySQL计算最长的不败连胜?(如何使用mysql计算最长的不败连胜次数)