斜杠反斜杠,日期字段中的连字符有什么区别?

时间:2017-03-23 10:54:53

标签: javascript html date datetime

为什么它会给出三种不同的结果?

var hyphen=new Date('2014-04-03').toUTCString();

var slash=new Date('2014/04/03').toUTCString();

var backslash=new Date('2014\04\03').toUTCString();


console.log('hyphen=      '+hyphen+ '\n' +'slash=       '+slash+ '\n' + 'backslash=   '+backslash);

1 个答案:

答案 0 :(得分:1)

MDN: Date

  

注意:由于浏览器差异和不一致,强烈建议不要使用Date构造函数(和Date.parse,它们是等效的)解析日期字符串。对RFC 2822格式字符串的支持仅限于惯例。对ISO 8601格式的支持不同之处在于,仅日期字符串(例如“1970-01-01”)被视为UTC,而不是本地。

除了from airflow import DAG from datetime import datetime, timedelta from airflow.contrib.hooks.ssh_hook import SSHHook from airflow.contrib.operators.ssh_execute_operator import SSHExecuteOperator from airflow.models import Variable default_args = { 'owner': 'airflow', 'depends_on_past': False, 'start_date': datetime.now(), 'email': ['my@email.com'], 'email_on_failure': True, 'retries': 0 } #server must be changed to point to the correct environment, to do so update DataQualitySSHHook variable in Airflow admin DataQualitySSHHook = Variable.get('DataQualitySSHHook') print('Connecting to: ' + DataQualitySSHHook) sshHookEtl = SSHHook(conn_id=DataQualitySSHHook) sshHookEtl.no_host_key_check = True #create dag dag = DAG( 'ed_data_quality_test-v0.0.3', #update version whenever you change something default_args=default_args, schedule_interval="0 0 * * *", dagrun_timeout=timedelta(hours=24), max_active_runs=1) #create tasks task1 = SSHExecuteOperator( task_id='run_remote_sp_audit_batch_register', bash_command="bash /opt/scripts/data_quality/EXEC_SP_AUDIT_BATCH.sh 'ED_DATA_QUALITY_MANUAL' 'REGISTER' '1900-01-01 00:00:00.000000' '2999-12-31 00:00:00.000000' ", #keep the space at the end ssh_hook=sshHookEtl, xcom_push=True, retries=0, dag=dag) task2 = SSHExecuteOperator( task_id='run_remote_sp_audit_module_session_start', bash_command="echo {{ ti.xcom_pull(task_ids='run_remote_sp_audit_batch_register') }}", ssh_hook=sshHookEtl, retries=0, dag=dag) #create dependencies task1.set_downstream(task2) \0字符,因此null等于'2014\04\03',其中'2014_4_3'是空字符。解析包含空字符作为日期的字符串的结果根本没有定义。