7 examples of 'pyspark convert string to timestamp' in Python

Every line of 'pyspark convert string to timestamp' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
75@staticmethod
76def convert_timestamp(str):
77
78 ts = time.strptime(str,'%a %b %d %H:%M:%S +0000 %Y')
79 ts = time.strftime('%Y-%m-%d %H:%M:%S', ts)
80
81 return ts
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

58def test_timestamp(self):
59 self.assertEqual(
60 _type_to_hql(StructField('value', TimestampType(), True).jsonValue()),
61 'timestamp',
62 )
7def timestamp_to_datetime(s):
8 """
9 Convert a Core Data timestamp to a datetime. They're all a float of seconds since 1 Jan 2001. We calculate
10 the seconds in offset.
11 """
12 if not s:
13 return None
14
15 OFFSET = (datetime.datetime(2001, 1, 1, 0, 0, 0) - datetime.datetime.fromtimestamp(0)).total_seconds()
16 return datetime.datetime.fromtimestamp(s + OFFSET)
30def converter(df: DataFrame) -> Series:
31 return df[field_name]
16def timestamp2datetime(timestamp: int):
17 date = datetime.datetime.fromtimestamp(timestamp / 1000)
18 return date
4def parse_timestamp(timestamp):
5 """Convert an ISO 8601 timestamp into a datetime."""
6 return datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S')
262def timestamp_parser(timestamp):
263 """Parse timestamp to datetime"""
264 return datetime.fromtimestamp(float(timestamp))

Related snippets