如何处理JWT.exp时间?

时间:2018-08-21 02:51:42

标签: javascript date jwt momentjs

TrainingsList

我有一个值为select ChoiceID, count(ChoiceID) as aValue from QuestionNumber inner join TestAnswer on QuestionNumber.QNID = TestAnswer.QNID where QuestionNumber.QuestionID = 30 group by ChoiceID order by aValue desc 的令牌,当我尝试使用console.log('DEBUG::+jwtDecode(token).exp', +jwtDecode(token).exp); //1534820211 console.log('DEBUG::try', new Date(+jwtDecode(token).exp).toISOString()); //DEBUG::try 1970-01-18T18:20:20.211Z 进行转换时,它给了我1534820211年。

但是,当我在jwt.io解码相同的令牌,并将鼠标悬停在toISOString()上时,它显示1970-01-18T18:20:20.211Z,这是巨大的区别。我还尝试过将exp传递到2018-08-21....并使用格式,但仍以jwtDecode(token).exp返回日期时间。

moment

1 个答案:

答案 0 :(得分:1)

您的值距纪元

JavaScript add_action( 'woocommerce_cart_calculate_fees', 'custom_cart_fee', 20, 1 ); function custom_cart_fee( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; // Set HERE your categories (can be term IDs, slugs or names) in a coma separated array $categories = array('649'); // Initializing $count = 0; // Loop through cart items foreach( $cart->get_cart() as $cart_item ) { if( has_term( $categories, 'product_cat', $cart_item['product_id'] ) ) { if( $cart_item['quantity'] >= 6 ){ $count++; } } } if ( $count >= 1 ) { $fee_amount = 2.50 * $count; $cart->add_fee( __( "Shipping fee", "woocommerce" ), $fee_amount, false ); // Last argument is related to enable tax (true or false) } } 构造函数(以及Date构造函数)从纪元开始以毫秒为单位接受值。将数字乘以1000,您的代码应该可以正常工作:

moment